Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Commit

Permalink
docs(docker): 学习WORKDIR指令
Browse files Browse the repository at this point in the history
  • Loading branch information
zjZSTU committed Sep 24, 2019
1 parent e3b10c3 commit e640954
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/source/docker/dockerfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Dockerfile指令
dockerfile/EXPOSE
dockerfile/ENV
dockerfile/ADD和COPY
dockerfile/ENTRYPOINT
dockerfile/ENTRYPOINT
dockerfile/WORKDIR
36 changes: 36 additions & 0 deletions docs/source/docker/dockerfile/WORKDIR.md
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.

0 comments on commit e640954

Please sign in to comment.