During my CI build I extract build artifacts from the build image in a multi-stage Docker build (test reports) by adding a LABEL build step and then creating a container with the labeled image to extract the artifact. This seems to be broken in Docker Desktop for Mac, or I misunderstand how this is supposed to work?
Here is a minimal build to reproduce the issue:
# Dockerfile.one
FROM alpine AS one
WORKDIR /test
RUN touch here
LABEL build=here
# Dockerfile.two
FROM alpine AS one
WORKDIR /test
RUN touch here
LABEL build=here
FROM alpine AS two
COPY --from=one /test/* /test/
RUN touch again
# test.sh
#! /bin/bash -u
# Clean up
trap 'rm -r test & docker rmi $image' EXIT
docker build -f $1 .
docker images --filter 'label=build=here'
image=$(docker images --filter 'label=build=here' -q | head -n 1)
id=$(docker create $image) && docker cp $id:/test/ . && docker rm $id
ls -l test
Running ./test.sh Dockerfile.one (only one stage) produces the expected output of the file here being present in the working directory.
However, running ./test.sh Dockerfile.two (multi-stage) fails, apparently because no images match --filter label=build=here.
What is wrong here?
$ docker version
Client:
Cloud integration: 1.0.17
Version: 20.10.7
API version: 1.41
Go version: go1.16.4
Git commit: f0df350
Built: Wed Jun 2 11:56:22 2021
OS/Arch: darwin/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: b0f5bc3
Built: Wed Jun 2 11:54:58 2021
OS/Arch: linux/amd64
Experimental: true