docker_practice/image/dockerfile/arg.md

69 lines
2.0 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 <参数名>=<值>`
2021-03-11 23:09:37 +08:00
使 `ARG` 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}
```