docker_practice/image/dockerfile/arg.md

69 lines
2.4 KiB
Go
Raw Normal View History

# ARG
`ARG <参数名>[=<默认值>]`
2017-02-18 21:02:39 +08:00
`ENV` `ARG` 使 `ARG` `docker history`
`Dockerfile` `ARG` `docker build` `--build-arg <参数名>=<值>`
1.13 `--build-arg` `Dockerfile` `ARG` `--build-arg` `Dockerfile` 使使退 1.13 退使 CI `Dockerfile` Dockerfile
ARG `FROM` `FROM`
```docker
ARG DOCKER_USERNAME=library
FROM ${DOCKER_USERNAME}/alpine
RUN set -x ; echo ${DOCKER_USERNAME}
```
使 Dockerfile `${DOCKER_USERNAME}` `FROM` `ARG`
```docker
# FROM
ARG DOCKER_USERNAME=library
FROM ${DOCKER_USERNAME}/alpine
# FROM 使
ARG DOCKER_USERNAME=library
RUN set -x ; echo ${DOCKER_USERNAME}
```
```docker
# FROM
ARG DOCKER_USERNAME=library
FROM ${DOCKER_USERNAME}/alpine
RUN set -x ; echo 1
FROM ${DOCKER_USERNAME}/alpine
RUN set -x ; echo 2
```
Dockerfile `FROM` 使 `${DOCKER_USERNAME}`使
```docker
ARG DOCKER_USERNAME=library
FROM ${DOCKER_USERNAME}/alpine
# FROM 使
ARG DOCKER_USERNAME=library
RUN set -x ; echo ${DOCKER_USERNAME}
FROM ${DOCKER_USERNAME}/alpine
# FROM 使
ARG DOCKER_USERNAME=library
RUN set -x ; echo ${DOCKER_USERNAME}
```