Skip to content

let parent ENV and child ARG have the same name #34494

Closed

Description

@andre-richter

Description

I have a parent Dockerfile:

FROM debian

ARG IMAGE_NAME
ENV IMAGE_NAME=$IMAGE_NAME

and a child Dockerfile:

FROM parent

ARG IMAGE_NAME
ENV IMAGE_NAME=$IMAGE_NAME

RUN echo $IMAGE_NAME

I 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:

  1. 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.):

Activity

  1. dedsm commented on Aug 24, 2017

    @dedsm

    I got bitten from this recently, I had to fall back to a ton of ONBUILD in the parent image because of this.

  2. andre-richter commented on Aug 24, 2017

    @andre-richter
    Author

    Unfortunately, if the base image is intended to also run as standalone and depends on the env variable, this workaround is not applicable :(

  3. dedsm commented on Aug 24, 2017

    @dedsm

    yes I know, and it sucks, I was about to create this issue but you came first.

  4. piwo1984 commented on Mar 26, 2018

    @piwo1984

    I've just stumbled over this issue for myself and wasted nearly a complete day on it.

  5. dedsm commented on Mar 26, 2018

    @dedsm

    probably it would be nice if people came up with their solutions on this, I hate mine

  6. sarink commented on Sep 4, 2018

    @sarink

    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_PATH which is already set by the ruby image. I simply renamed the argument like so:

    ARG ARG_BUNDLE_PATH
    ENV BUNDLE_PATH=$ARG_BUNDLE_PATH
    

    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.

  7. andre-richter commented on Sep 4, 2018

    @andre-richter
    Author

    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.

  8. Wu-Jing commented on May 2, 2019

    @Wu-Jing

    I just ran into the same issue. 😫
    A warning as suggested above would have greatly reduced the time spent on debug the issue.

  9. gingerlime commented on Jun 14, 2019

    @gingerlime

    Also bumped into this. Using a different ARG name feels soooo ugly. It really feels like a bug...

  10. flatline-studios commented on Oct 17, 2019

    @flatline-studios

    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:

    FROM mariadb
    
    ARG GPG_KEYS
    ENV GPG_KEYS=${GPG_KEYS}
    
    RUN echo ${GPG_KEYS}
    

    Then, I run:

    docker build --build-arg GPG_KEYS=test .
    

    I get:

    177F4010FE56CA3336300305F1656F24C74CD1D8
    

    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!

  11. tiborvass commented on Feb 6, 2020

    @tiborvass
    Contributor

    This is fixed by enabling buildkit (next gen builder) when running builds: DOCKER_BUILDKIT=1.

  12. espears1 commented on Feb 25, 2020

    @espears1

    @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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions