Open lsierant opened 2 years ago
I was facing this issue too. I was building a linux/amd64
image on M1 mac.
The docker build command in cli worked fine, but using docker-py to build it doesn't work. I am providing --platform=linux/amd64
in both cli and docker-py
I suspected it to be a cache issue, so I tried setting nocache=True. But that didn't work.
Finally, what worked was removing the base image and letting the build process download the base image again
docker image rm <base_image:tag>
I am facing the same issue without any mention of ARG
in Dockerfile
Steps to reproduce:
docker pull --platform=linux/arm64/v8 python:3.9
FROM --platform=linux/amd64 python:3.9
CMD ["tail", "-f", "/dev/null"]
and
client.api.build(decode=True, path=".", tag=tag, platform="linux/amd64", dockerfile="./Dockerfile")
Like others said the only fix that works is to delete the base image. Docker CLI works correctly regardless.
You can achieve the purpose of cleaning the base image and cache by adding --pull and --no-cache flags
docker build -t <...> . --platform "linux/amd64" --pull --no-cache
And this will ultimately solve the issue
Problem occured when building
linux/amd64
image (by setting platform parameter) on M1 mac for different arch. I isolated a case for this bug and found workaround.The problem is when building an image which has:
scratch
as a base imageThe problem does not occur when the base image is changed to anything else (e.g. ubuntu), or platform switch is not set, or there is different first op than ARG.
Build fails from code Dockerfile:
Run with code:
Results in:
Build succeeds from cli The same dockerfile built from cli is working correctly.
Workaround It seems that this error occurs only when having scratch image as a base and ARG as a second command. After swapping ARG and ADD lines the image is building. Also changing the base image to anything different than scratch is working.
Results in:
Steps to recreate I created sample project when trying to pin down the issue: https://github.com/lsierant/playground-docker-py
git clone https://github.com/lsierant/playground-docker-py.git
./run-test.sh
(setups venv and runs test.py)Environment I tested it on M1 mac (building linux/arm64) and on linux machine building arm64 image.
pip freeze | grep docker && python --version && docker version