moby / moby/moby

ARG is ignored if it has the same name of an ENV variable in a FROM image

Open
#45,228 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/builder area/builder/classic-builder kind/bug version/20.10
Dominant language
Go
Stars
72.1k
Forks
19.2k
Avg merge
1d 18h
Merged PRs (30d)
164

Description

Description

ARG is ignored if it has the same name of an ENV variable in a FROM image, but only on Community Edition 20.10.23/containerd 1.6.16. Works instead on Desktop Edition 20.10.23/containerd 1.6.18

Reproduce

Dockerfile:

# Build golang
FROM golang:1.19.5-bullseye as basic

ENV VARIABLE="basic_value"
RUN echo BASIC VARIABLE ${VARIABLE}

FROM basic

ARG VARIABLE
ENV VARIABLE=$VARIABLE

RUN echo NEW VARIABLE ${VARIABLE}

command:

docker build --build-arg VARIABLE=new_value .

Works fine in Desktop version:

> docker build --build-arg VARIABLE=new_value .
[+] Building 1.0s (7/7) FINISHED                                                                                                                                         
 => [internal] load build definition from Dockerfile                                                                                                                0.0s
 => => transferring dockerfile: 38B                                                                                                                                 0.0s
 => [internal] load .dockerignore                                                                                                                                   0.0s
 => => transferring context: 2B                                                                                                                                     0.0s
 => [internal] load metadata for docker.io/library/golang:1.19.5-bullseye                                                                                           0.8s
 => [basic 1/2] FROM docker.io/library/golang:1.19.5-bullseye@sha256:78b1726316ebfdec022fe7628f07547cafcd2d8a3934288187b87173f75925bc                               0.0s
 => CACHED [basic 2/2] RUN echo BASIC VARIABLE **basic_value**                                                                                                          0.0s
 => CACHED [stage-1 1/1] RUN echo NEW VARIABLE **new_value**                                                                                                            0.0s
 => exporting to image                                                                                                                                              0.0s
 => => exporting layers                                                                                                                                             0.0s
 => => writing image sha256:dc6502d41c9927109ef7fce33c02cc4fe5318438a9b76f100754812ee691032d  

Does not override the value in Community Version (raw log) - outputs basic_value rather than new_value:

+ docker build --build-arg VARIABLE=new_value overlaymgr/ci/binary
Sending build context to Docker daemon  4.096kB

Step 1/7 : FROM golang:1.19.5-bullseye as basic
1.19.5-bullseye: Pulling from library/golang

...

Digest: sha256:78b1726316ebfdec022fe7628f07547cafcd2d8a3934288187b87173f75925bc
Status: Downloaded newer image for golang:1.19.5-bullseye
 ---> 52d8a3cc7dee
Step 2/7 : ENV VARIABLE="basic_value"
 ---> Running in cc5c4752755b
Removing intermediate container cc5c4752755b
 ---> b48248036a80
Step 3/7 : RUN echo BASIC VARIABLE ${VARIABLE}
 ---> Running in 1fc1934f78d8
BASIC VARIABLE **basic_value**
Removing intermediate container 1fc1934f78d8
 ---> 18e8a23e85d9
Step 4/7 : FROM basic
 ---> 18e8a23e85d9
Step 5/7 : ARG VARIABLE
 ---> Running in e61ce93c43bf
Removing intermediate container e61ce93c43bf
 ---> ad91b55894ba
Step 6/7 : ENV VARIABLE=$VARIABLE
 ---> Running in 047d071e1533
Removing intermediate container 047d071e1533
 ---> 52885e7bbc5e
Step 7/7 : RUN echo NEW VARIABLE ${VARIABLE}
 ---> Running in 3ce66b323c7d
NEW VARIABLE **basic_value**
Removing intermediate container 3ce66b323c7d
 ---> e416cd5ab731
Successfully built e416cd5ab731
Expected behavior

Behavior should be consistent across versions - we prefer the version where the ARG is used even if it has the same name of an already defined ENV variable (Desktop Edition)

docker version

Working version:

docker version
Client: Docker Engine - Community
 Cloud integration: v1.0.31
 Version:           20.10.23
 API version:       1.41
 Go version:        go1.18.10
 Git commit:        7155243
 Built:             Thu Jan 19 17:34:13 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop
 Engine:
  Version:          20.10.23
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.10
  Git commit:       6051f14
  Built:            Thu Jan 19 17:32:04 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.18
  GitCommit:        2456e983eb9e37e47538f59ea18f2043c9a73640
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Non working version:

Client: Docker Engine - Community
 Version:           20.10.23
 API version:       1.41
 Go version:        go1.18.10
 Git commit:        7155243
 Built:             Thu Jan 19 17:34:12 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.23
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.10
  Git commit:       6051f14
  Built:            Thu Jan 19 17:32:03 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.16
  GitCommit:        31aa4358a36870b21a992d3ad2bef29e1d693bec
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
docker info

Working version:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.10.3)
  compose: Docker Compose (Docker Inc., v2.15.1)
  dev: Docker Dev Environments (Docker Inc., v0.1.0)
  extension: Manages Docker extensions (Docker Inc., v0.2.18)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.25.0)
  scout: Command line tool for Docker Scout (Docker Inc., v0.6.0)

Server:
 Containers: 3
  Running: 1
  Paused: 0
  Stopped: 2
 Images: 26
 Server Version: 20.10.23
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2456e983eb9e37e47538f59ea18f2043c9a73640
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.15.90.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 31.31GiB
 Name: docker-desktop
 ID: XUZA:3WJX:3XPH:ABDK:ZFOP:3QJY:2O53:6NNP:OLF6:J6KJ:EMIN:QS5B
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support

Non Working version:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.10.0-docker)
  scan: Docker Scan (Docker Inc., v0.23.0)


 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 31aa4358a36870b21a992d3ad2bef29e1d693bec
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.4.0-1101-azure
 Operating System: Ubuntu 18.04.6 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 15.63GiB
 Name: 210338f3c000000
 ID: FMML:BZTN:ZZ3O:3ZL4:562G:R4IW:LK22:MPQ2:PNDI:MGLO:XEJM:GPYQ
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: 1eshostedagent
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No swap limit support
Additional Info

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied Dockerfile and build command on the Community and Desktop configurations described in the issue. Trace Docker's handling of ARG and ENV across the FROM stages, then add or update a regression test so the build consistently outputs new_value when the build argument is supplied.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
build-system, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.