✦ For everyone, free.

Practical knowledge for real and everyday life

Home

3.3.1.3 Alpine Base Images

A focused guide to Alpine Base Images, connecting core concepts with practical Docker and container operations.

Alpine base images provide an extremely small Linux distribution built around the musl C library and the apk package manager, popular specifically for producing minimal container images, though with some compatibility tradeoffs compared to glibc-based distributions.

Why Alpine Images Are So Small

Alpine's small footprint comes from deliberate minimalism: it ships without many of the default packages and documentation that larger distributions include, and its use of musl instead of glibc further reduces the base image's size.

docker images alpine
docker images debian:bookworm-slim

Comparing these reported sizes typically shows Alpine as dramatically smaller, often by an order of magnitude or more, than even a slim variant of a glibc-based distribution.

Installing Packages With apk

Alpine's package manager, apk, provides a similarly straightforward way to install additional software, with a syntax distinct from apt or yum.

FROM alpine:3.19
RUN apk add --no-cache curl

The --no-cache flag avoids leaving behind package index data that would otherwise need to be separately cleaned up to keep the layer minimal.

The musl Compatibility Tradeoff

Because Alpine uses musl instead of glibc, pre-built binary packages compiled against glibc may not run correctly, or at all, on an Alpine base, which is a meaningful consideration for languages or dependencies that frequently distribute glibc-compiled binaries.

docker run --rm alpine ldd --version

This reports musl, distinctly different from what the same command would report on a Debian or Ubuntu-based image, explaining why some binary packages built for glibc need to be rebuilt, rather than directly installed, on Alpine.

When Alpine Is the Right Choice

Alpine is an excellent choice when minimizing image size matters significantly and the application's dependencies are known to be compatible with musl, which is increasingly common but still worth verifying explicitly rather than assuming.

FROM node:20-alpine
Why Alpine Base Images Matter

Alpine's combination of minimal size and active maintenance has made it one of the most popular choices for production images specifically, though its compatibility tradeoffs are worth testing for explicitly rather than discovering only after a dependency fails unexpectedly.