Repository navigation
Closed
Labels
Description
Description
I have a parent Dockerfile:
FROM debian
ARG IMAGE_NAME
ENV IMAGE_NAME=$IMAGE_NAMEand a child Dockerfile:
FROM parent
ARG IMAGE_NAME
ENV IMAGE_NAME=$IMAGE_NAME
RUN echo $IMAGE_NAMEI build with:
docker build --build-arg IMAGE_NAME=parent -t parent -f Dockerfile.parent .
docker build --build-arg IMAGE_NAME=child -t child -f Dockerfile.child .Steps to reproduce the issue:
- Use files shown before and build
Describe the results you received:
The RUN command in the second container outputs parent, because the ARG IMAGE_NAME is ignored, since it exists as an ENV in the parent file.
Describe the results you expected:
Changing the name of ARG in the second container resolves this problem, but is this a bug or a feature? I would suspect ARG IMAGE_NAME to overload $IMAGE_NAME at least for the scope of the child Dockerfile.
Additional information you deem important (e.g. issue happens only occasionally):
Output of docker version:
Client:
Version: 17.06.0-ce
API version: 1.30
Go version: go1.8.3
Git commit: 02c1d87
Built: Fri Jun 23 21:23:31 2017
OS/Arch: linux/amd64
Server:
Version: 17.06.0-ce
API version: 1.30 (minimum version 1.12)
Go version: go1.8.3
Git commit: 02c1d87
Built: Fri Jun 23 21:19:04 2017
OS/Arch: linux/amd64
Experimental: false
Output of docker info:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 69
Server Version: 17.06.0-ce
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 46
Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfb82a876ecc11b5ca0977d1733adbe58599088a
runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4
init version: 949e6fa
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.4.0-89-generic
Operating System: Ubuntu 16.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 31.25GiB
Name: precision
ID: Q2ND:NM4A:LDKO:MW5R:4MJA:2ERU:MC67:ZZUY:D66G:PBFA:23O3:YCOC
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No swap limit support
Additional environment details (AWS, VirtualBox, physical, etc.):
Reacted by LetsThinkAboutIT, Avika Narula, Jared Walters, Sergei Kirjanov, Brett Randall and Akito
Activity
dedsm commentedon Aug 24, 2017
I got bitten from this recently, I had to fall back to a ton of ONBUILD in the parent image because of this.
andre-richter commentedon Aug 24, 2017
Unfortunately, if the base image is intended to also run as standalone and depends on the env variable, this workaround is not applicable :(
dedsm commentedon Aug 24, 2017
yes I know, and it sucks, I was about to create this issue but you came first.
piwo1984 commentedon Mar 26, 2018
I've just stumbled over this issue for myself and wasted nearly a complete day on it.
dedsm commentedon Mar 26, 2018
probably it would be nice if people came up with their solutions on this, I hate mine
sarink commentedon Sep 4, 2018
Does the solution need to be more complicated than just changing the name of your arg? I recently got bit by this when trying to override
BUNDLE_PATHwhich is already set by therubyimage. I simply renamed the argument like so:and all's well.
The only trouble was how long it took me to find this issue 😫
There should really be some sort of warning from the docker internals, not sure if that's actually possible though.
andre-richter commentedon Sep 4, 2018
I second that.
It should either overwrite with warning, or not overwrite with warning.
But please help the user with some prints to figure this out.
Wu-Jing commentedon May 2, 2019
I just ran into the same issue. 😫
A warning as suggested above would have greatly reduced the time spent on debug the issue.
gingerlime commentedon Jun 14, 2019
Also bumped into this. Using a different ARG name feels soooo ugly. It really feels like a bug...
flatline-studios commentedon Oct 17, 2019
Just encountered this too.
The big problem with this (as far as I can see), is that you might not know all the ENV names that have come before it (parents, grandparents, ..., ad infinitum).
For example, take the following
Dockerfile:Then, I run:
I get:
This really feels like a scope bug... If I'm building several images deep, I have to remember every ENV variable's name that's come before? Even if (like in my example), I'm building from someone else's image!? Insane!
tiborvass commentedon Feb 6, 2020
This is fixed by enabling buildkit (next gen builder) when running builds: DOCKER_BUILDKIT=1.
espears1 commentedon Feb 25, 2020
@tiborvass Thank you for mentioning a possible fix.
Can you clarify to which versions of Docker the buildkit fix would apply? I ran into this bug today, but it's unclear from your comment if the fix could work for me. It's in a production environment so it's quite costly for me to try it out and I'd like more clarity around the scope of the solution and compatibility before sinking the time to test it, if you have a chance to elaborate, or link to any docs where you might have discovered this?