docker / docker/cli

[bug] Build args are not resolved over multi-stage build

Open
#3,533 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/builder area/builder/classic-builder
Dominant language
Go
Stars
6.1k
Forks
2.2k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

Description

ARG commands evaluate to different things in multi-stage builds on macOS (Docker Desktop 20.10.13) and Linux (20.10.14).

Steps to reproduce the issue:
1.

FROM alpine:latest as base
ARG NAME="1234"
RUN echo "base:: $NAME"  
FROM base AS base-dev
ARG NAME
RUN echo "dev:: $NAME"  
FROM base-dev as base-custom
ARG NAME
RUN echo "custom::" $NAME
  1. docker build --progress=plain .
  2. Check output of custom::

Describe the results you received:

On Docker Desktop on macOS 20.10.13:

Step 9/9 : RUN echo "custom::" $NAME
 ---> Running in 1c484bcc731d
custom:: 1234

On Linux 20.10.14:

Step 9/9 : RUN echo "custom::" $NAME
 ---> Running in 1c484bcc731d
custom:: 

Describe the results you expected:

On Linux the output should be also

custom:: 1234

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

Docker version 20.10.14, build a224086 (LINUX)
Docker version 20.10.13, build a224086 (macOS)

Output of docker info:

Linux:

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

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 76
 Server Version: 20.10.14
 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: 3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc version: v1.0.3-0-gf46b6ba
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.4.0-107-generic
 Operating System: Ubuntu 20.04.4 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 32
 Total Memory: 62.79GiB
 Name: gabyx-linux
 ID: T4P2:2KQP:6FOQ:YQKN:JXOK:XXD4:XPRY:IA4S:4QOP:B2MQ:XJUI:AFJR
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: gabyxgabyx
 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

macOS:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.8.1)
  compose: Docker Compose (Docker Inc., v2.3.3)
  regctl: Manage docker registries (regclient, 0.1)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 2
  Running: 1
  Paused: 0
  Stopped: 1
 Images: 25
 Server Version: 20.10.13
 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: 2
 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: 2a1d4dbdb2a1030dc5b01e96fb110a9d9f150ecc
 runc version: v1.0.3-0-gf46b6ba
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.104-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 9.73GiB
 Name: docker-desktop
 ID: REL6:ZZ3C:NB2L:Y7Q4:VMEY:BNLB:56PT:4S6U:62QD:Z4HU:UDO3:RK7S
 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:5000
  localhost:5000
  127.0.0.0/8
 Live Restore Enabled: false

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

Reproduce the issue with the provided multi-stage Dockerfile and run docker build --progress=plain . to compare the custom:: output across environments. Start by tracing how the Docker CLI handles build arguments across stages; done means the final stage resolves NAME to 1234 consistently.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.