You should have access to and be able to append to ENV
variables in Dockerfiles:
ENV MyVar=${MyVar}-modified
Test base Dockerfile, built with: docker build -t base -f Dockerfile.base .
# Dockerfile.base
FROM alpine:3.9
ENV Version=v1.0
Test child Dockerfile built with docker build -t child -f Dockerfile.child .
# Dockerfile.child
FROM base:latest
ENV Version=${Version}-alpha
RUN echo ${Version}
The build output showed that the Version
variable was read from the base and added to in the child:
...
=> [internal] load build definition from Dockerfile
=> [1/2] FROM docker.io/library/base:latest 0.0s
=> [2/2] RUN echo v1.0-alpha 0.0s
...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…