Builder fails when building `FROM scratch` and `ARG` is the second line in Dockerfile
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 72.1k
- Forks
- 19.2k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 164
Description
Description
Build is failing with the following error
failed to get destination image "sha256:d713c98f66880c8411b0d55a019d6aac2f45cfc57a48eae50701610d7e3ecf56": image with reference sha256:d713c98f66880c8411b0d55a019d6aac2f45cfc57a48eae50701610d7e3ecf56 was found but does not match the specified platform: wanted linux/arm/v6, actual: linux/amd64
Reproduce
Given a Dockerfile
FROM scratch
ARG myArg
ADD files-${myArg}.tar.gz /
Start a build with docker build --platform=linux/arm/v6 --build-arg myArg=some -t myImg .
Yeilds following output:
docker build --platform=linux/arm/v6 --build-arg myArg=some -t myImg .
Sending build context to Docker daemon 29.67MB
Step 1/13 : FROM scratch
--->
Step 2/13 : ARG myArg
---> Running in 06d61fdbc7b5
Removing intermediate container 06d61fdbc7b5
---> d713c98f6688
Step 3/13 : ADD files-${myArg}.tar.gz /
failed to get destination image "sha256:d713c98f66880c8411b0d55a019d6aac2f45cfc57a48eae50701610d7e3ecf56": image with reference sha256:d713c98f66880c8411b0d55a019d6aac2f45cfc57a48eae50701610d7e3ecf56 was found but does not match the specified platform: wanted linux/arm/v6, actual: linux/amd64
Adding --no-chache does not change anything.
Now, let's add some command before ARG
Dockerfile
FROM scratch
ADD qwe /
ARG myArg
ADD files-${myArg}.tar.gz /
docker build --platform=linux/arm/v6 --build-arg myArg=some -t myImg .
Sending build context to Docker daemon 29.67MB
Step 1/4 : FROM scratch
--->
Step 2/4 : ADD qwe /
---> 4ed4fd43b443
Step 3/4 : ARG myArg
---> [Warning] The requested image's platform (linux/arm/v6) does not match the detected host platform (linux/amd64) and no specific platform was requested
---> Running in cc1b822df5aa
Removing intermediate container cc1b822df5aa
---> 0b548c74b5cc
Step 4/4 : ADD files-${myArg}.tar.gz /
---> 891efb6b6913
Successfully built 891efb6b6913
Successfully tagged myImg
Expected behavior
docker build should not fail
docker version
Client:
Version: 20.10.5+dfsg1
API version: 1.41
Go version: go1.15.15
Git commit: 55c4c88
Built: Mon May 30 18:34:49 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.5+dfsg1
API version: 1.41 (minimum version 1.12)
Go version: go1.15.15
Git commit: 363e9a8
Built: Mon May 30 18:34:49 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.13~ds1
GitCommit: 1.4.13~ds1-1~deb11u4
runc:
Version: 1.0.0~rc93+ds1
GitCommit: 1.0.0~rc93+ds1-5+deb11u2
docker-init:
Version: 0.19.0
GitCommit:
docker info
Client:
Context: default
Debug Mode: false
Server:
Containers: 2
Running: 0
Paused: 0
Stopped: 2
Images: 54
Server Version: 20.10.5+dfsg1
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: systemd
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: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
Default Runtime: runc
Init Binary: docker-init
containerd version: 1.4.13~ds1-1~deb11u4
runc version: 1.0.0~rc93+ds1-5+deb11u2
init version:
Security Options:
apparmor
seccomp
Profile: default
cgroupns
Kernel Version: 5.10.0-23-amd64
Operating System: Debian GNU/Linux 11 (bullseye)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.761GiB
Name: debian
ID: QDFR:I4CX:AVE2:NJ5Q:LGOQ:VQCA:JGY2:7VVC:HJIW:UOJL:224W:LVV7
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: Support for cgroup v2 is experimental
Additional Info
Same issue is being described here https://github.com/docker/docker-py/issues/2990
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the two Dockerfile examples and the docker build command using --platform=linux/arm/v6 and --build-arg. Start by tracing builder handling of ARG after FROM scratch, ADD, and platform metadata, comparing the failing and succeeding Dockerfiles. Done means the original Dockerfile builds successfully for the requested platform without requiring an extra command before ARG.
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
- 38/100