I just realized today that the default docker.io package from Ubuntu is seriously limited, compared with the one provided by Docker Inc with their docker-ce (community edition).
For example, with the following Dockerfile, the Ubuntu’s version of docker would build all intermediate stages, including test-stage, while with Docker Engine packages from docker-ce the test-stage will be skipped (which is more desirable).
# syntax=docker/dockerfile:1
FROM alpine:latest AS build-stage
RUN echo "Installing build tools..."
RUN mkdir /app
RUN touch /app/artifact.txt
FROM alpine:latest AS test-stage
RUN echo "Running tests..."
# This stage is only run if explicitly targeted
FROM alpine:latest AS production
COPY --from=build-stage /app/artifact.txt /app/artifact.txt
CMD ["cat", "/app/artifact.txt"]
To properly installed the docker.io and its companion packages, just follow this page. The output for running the above Dockerfile will look like below with docker-ce packages.
jsun@dev:~/temp$ docker build . -t mytest
[+] Building 1.5s (11/11) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 419B 0.0s
=> resolve image config for docker-image://docker.io/docker/dockerfile:1 0.7s
=> CACHED docker-image://docker.io/docker/dockerfile:1@sha256:b6afd42430b15f2d2a4c5a02b919e98a525b785b1aaff16747d2f623364e39b6 0.0s
=> => resolve docker.io/docker/dockerfile:1@sha256:b6afd42430b15f2d2a4c5a02b919e98a525b785b1aaff16747d2f623364e39b6 0.0s
=> [internal] load metadata for docker.io/library/alpine:latest 0.3s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [build-stage 1/4] FROM docker.io/library/alpine:latest@sha256:51183f2cfa6320055da30872f211093f9ff1d3cf06f39a0bdb212314c5dc7375 0.0s
=> => resolve docker.io/library/alpine:latest@sha256:51183f2cfa6320055da30872f211093f9ff1d3cf06f39a0bdb212314c5dc7375 0.0s
=> CACHED [build-stage 2/4] RUN echo "Installing build tools..." 0.0s
=> CACHED [build-stage 3/4] RUN mkdir /app 0.0s
=> CACHED [build-stage 4/4] RUN touch /app/artifact.txt 0.0s
=> CACHED [production 2/2] COPY --from=build-stage /app/artifact.txt /app/artifact.txt 0.0s
=> exporting to image 0.1s
=> => exporting layers 0.0s
=> => exporting manifest sha256:cfce1f88ad86e2d55be2ea639e9ccbee74e6feae06ff46d6a6f6efbe7b4e4f30 0.0s
=> => exporting config sha256:f6db73b62eabd225c8916c02941c7389b510781cba6e8308c80036cde6a9d4f9 0.0s
=> => exporting attestation manifest sha256:1b3ada3c9b1c771e50fbbb44962ee1baaaf659b635a66302d0c25b5fe484c86e 0.1s
=> => exporting manifest list sha256:44066fc8f168c1d0508e4ceca10171a3a1623deb7cbc813f97aeec5df4faa3c9 0.0s
=> => naming to docker.io/library/mytest:latest 0.0s
=> => unpacking to docker.io/library/mytest:latest
