Sub topic 9
Where minimal images break: native extensions, DNS, locales, and certificates
This chapter assumes you can write a Dockerfile, know the difference between glibc and musl from earlier chapters, and know that a native extension is compiled C code loaded by a language runtime. Minimal images fail in a few predictable ways. Knowing them lets you diagnose a failure quickly instead of switching base images at random.
Native extensions
Many Python packages ship prebuilt wheels tagged manylinux, which target glibc. On Alpine, pip cannot use those wheels. It uses a musllinux wheel if the project publishes one. Otherwise it builds from source, which needs a compiler and headers that Alpine does not include.
FROM python:3.12-alpine AS build
RUN apk add --no-cache build-base libffi-dev
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
FROM python:3.12-alpine
COPY --from=build /install /usr/local
COPY . /app
WORKDIR /app
CMD ["python", "app.py"]The compiler stays in the build stage. The cost is a longer build and the risk of subtle behavior differences, because the extension now runs against musl.
Node has the same problem. Packages with prebuilt binaries often publish separate glibc and musl variants, and some publish only glibc. A glibc binary on Alpine usually fails with not found or a loader error, even though the file exists. The error message names the missing dynamic loader, not your file.
Distroless images with a glibc userland (base-debian12) run glibc binaries. The static variant has no libc at all, so it only runs statically linked programs. A Go build with CGO_ENABLED=0 fits it. A build with cgo enabled does not.
DNS
musl's resolver differs from glibc's. Older musl versions had no TCP fallback for large DNS responses. Newer versions add it, but you should check the Alpine release you use. musl also handles search domains and ndots differently from glibc. In Kubernetes, where ndots:5 is the default, a short name such as db can resolve on a Debian image and fail or behave differently on Alpine. Symptoms are intermittent lookup failures or slow first connections. Test with the same resolver configuration you use in production. Using a fully qualified name with a trailing dot avoids the search list.
Locales and time zones
Debian slim images ship only the C, C.UTF-8 and POSIX locales. Setting LANG=en_US.UTF-8 has no effect until you install and generate that locale. musl has minimal locale support, so programs that rely on locale-aware sorting or formatting behave differently on Alpine.
Time zone data is a separate package. If time.LoadLocation("Europe/Berlin") in Go or ZoneInfo("Europe/Berlin") in Python fails, the image lacks tzdata. Install it, or use a base that includes it. Distroless static includes tzdata.
Certificates
Outbound HTTPS needs a CA bundle. Bare debian:bookworm-slim does not include ca-certificates. A request then fails with a certificate verification error such as x509: certificate signed by unknown authority.
FROM debian:bookworm-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates tzdata \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build /out/app /app
ENTRYPOINT ["/app"]Distroless static and base include CA certificates, so no change is needed there. If you build from scratch, copy /etc/ssl/certs/ca-certificates.crt from the build stage yourself.
A triage order
Exercise
A Go service builds with CGO_ENABLED=1 and runs in gcr.io/distroless/static-debian12. It exits at startup with a "not found" style error. Why, and what are two ways to fix it?
Show answer
The static image has no libc, but the cgo binary is dynamically linked against glibc. One fix is to build with CGO_ENABLED=0 so the binary is static. The other is to run on a glibc-based image such as gcr.io/distroless/base-debian12.