Nuances about docker.io on Ubuntu 24.04

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        

Build leveldb v1.22 for latest Alpine Linux (3.20)

Alpine Linux is a popular choice for building docker. Since v3.17, leveldb version is bumped from v1.22 to v1.23, where the new version disabled rtti, which caused many packages to break, including popular python module, plyvel. I encountered this problem when building electrumX docker image. Googling around I realize this is a popular problem and there are no easy and obvious solutions.

I decided to simply build apk files for leveldb v1.22 against the latest alpine linux, which is 3.20 today.

Steps:

  1. Mostly follow an excellent tutorial at fudex.org on setting up the docker build environment.
  2. Check out aports at alpine version v3.16, (host) git clone –depth=1 https://gitlab.alpinelinux.org/alpine/aports -b 3.16-stable aports-3.16
  3. Copy over leveldb APKBUILD file over to the latest 3.20 aports, (host) cp -a aports-3.16/main/leveldb aports/main/
  4. go back to alpine-dev container and build the package files
    1. (alpine-dev) cd ~/aports/main/leveldb
    2. (alpine-dev) abuild -r

The file APK files are located under ~/packages/main/x86_64. For convenience, I have include those two files below. Of course, you should strip the “.bin” suffix before using them. I had to add the suffix to work around wordpress restrictions. Please refer to this docker file to see how these files are used in a real case.