This repository has been archived by the owner on Mar 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
# WORKDIR | ||
|
||
参考:[WORKDIR](https://docs.docker.com/engine/reference/builder/#workdir) | ||
|
||
`WORKDIR`指令为`RUN,CMD,ENTRYPOINT,COPY`和`ADD`指令设置了工作路径 | ||
|
||
## 语法 | ||
|
||
``` | ||
WORKDIR /path/to/workdir | ||
``` | ||
|
||
* `Dockerfile`文件中可以设置多条`WORKDIR`指令,其作用于后续的指令 | ||
* 可以设置`WORKDIR`为相对路径,其相对于上一条`WORKDIR`指令的路径 | ||
* 可以使用`ENV`设定的环境变量 | ||
|
||
## 示例 | ||
|
||
|
||
``` | ||
WORKDIR /a | ||
WORKDIR b | ||
WORKDIR c | ||
RUN pwd | ||
``` | ||
|
||
最后的`pwd`命令输出为`/a/b/c` | ||
|
||
``` | ||
ENV DIRPATH /path | ||
WORKDIR $DIRPATH/$DIRNAME | ||
RUN pwd | ||
``` | ||
|
||
最后的`pwd`命令输出为`/path/$DIRNAME` |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.