Open theelderbeever opened 2 years ago
This is a known limitation of the classic (non-buildkit) builder; with work in progress to make BuildKit the default builder (for Docker Desktop, this is already the case, but not yet for Linux installs), I'm not sure if this will be addressed.
Here's the example that's provided above, but with BuildKit used;
DOCKER_BUILDKIT=1 docker build -t parent:latest -f parent.dockerfile .
[+] Building 0.1s (5/5) FINISHED
=> [internal] load build definition from parent.dockerfile 0.0s
=> => transferring dockerfile: 83B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/alpine:latest 0.0s
=> CACHED [1/1] FROM docker.io/library/alpine:latest 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:04ee7e261e91f63c023b9d72dc33890c2ec33845ef07e3d8ba9b5bb8484ec256 0.0s
=> => naming to docker.io/library/parent:latest 0.0s
Then, building the "child" image (I'm using --progress=plain
to show the output of each step;
DOCKER_BUILDKIT=1 docker build -t child:latest --progress=plain --build-arg HELLO=Earth -f child.dockerfile --no-cache .
#1 [internal] load build definition from child.dockerfile
#1 transferring dockerfile:
#1 transferring dockerfile: 101B done
#1 DONE 0.0s
#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.0s
#3 [internal] load metadata for docker.io/library/parent:latest
#3 DONE 0.0s
#4 [1/2] FROM docker.io/library/parent:latest
#4 CACHED
#5 [2/2] RUN echo "HELLO=Earth"
#5 0.304 HELLO=Earth
#5 DONE 0.3s
#6 exporting to image
#6 exporting layers 0.1s done
#6 writing image sha256:6d2aa4b9d3e6a05b1341f66a5af77631e7b21bc43aad18c50491d565d4160074
#6 writing image sha256:6d2aa4b9d3e6a05b1341f66a5af77631e7b21bc43aad18c50491d565d4160074 done
#6 naming to docker.io/library/child:latest done
#6 DONE 0.1s
If possible, I'd recommend using BuildKit for your builds (easiest way to enable that is to set DOCKER_BUILDKIT=1
in your shell, or add it to your shell's profile)
Ah understood and thank you. Unfortunately, due to the environment we use specifically we can't use build kit because of the x503 self signed certificate issue with build kit and private registries. Good to know this particular issue is solved though going forward.
Unfortunately, due to the environment we use specifically we can't use build kit because of the x503 self signed certificate issue with build kit and private registries.
Hmm.. good one; I recall this being more of an issue when using the docker-container
driver, but perhaps I'm mistaken; @crazy-max can you fill me in on that one? (are there still issues to fix for that?)
Description
ARG
variables of the same name as an environment variable set in a base image do not overwrite the value of the variable during build time. Is it intentional for the primary environment to take precedence over the temporary environment? This is especially irritating when a base image sets a proxy value to empty and the child image needs to temporarily set a build environment that uses a different proxy value than the parent image.Steps to reproduce the issue:
Describe the results you received:
Create parent dockerfile and set an ENV variable.
Build the parent image
Create a child dockerfile and set a build-arg with the same name as the ENV var from parent.
Build the child image.
Result: In
Step 3/4
the value echo'd is that of the original ENV var in the parent.Describe the results you expected: I would expect that the temporary environment would take precedence over the core environment during build and echo would produce
HELLO=Earth
in the example above.Additional information you deem important (e.g. issue happens only occasionally):
Output of
docker version
:Output of
docker info
:Additional environment details (AWS, VirtualBox, physical, etc.):