cheat-sheets

Alpine Linux

Alpine is a small musl libc and BusyBox based distribution; the alpine image is about 13 MB. Use it for small images where the software is known to work on musl.

Documentation: Alpine Linux Wiki Project: Alpine Linux · Docker Hub

See also Container Distros and Dockerfile.

apk Package Manager #

COMMANDDESCRIPTION
apk add --no-cache PACKAGEInstall without keeping an index cache (use this in Dockerfiles)
apk add --no-cache --virtual .build-deps build-baseInstall build tools as a named group
apk del .build-depsRemove that group after building
apk updateRefresh the package index (not needed with --no-cache)
apk upgrade --no-cacheUpgrade installed packages
apk search -q PATTERNSearch packages by name
apk info -W /PATH/TO/FILEWhich package owns a file
apk info -vList installed packages with versions
apk list -IList installed packages
apk add --no-cache PACKAGE=VERSIONPin a version (must exist in the repository)

Image Tags #

TAGMEANING
alpine:3.22A specific release (preferred for reproducible builds)
alpine:3Latest 3.x release
alpine:latestNewest stable release; avoid in builds
alpine:edgeRolling development branch

Pin the release: old package versions are removed from the repositories, so an unpinned apk add can break later.

Users and Groups #

COMMANDDESCRIPTION
adduser -D -u 10001 APPCreate user APP with no password and a fixed UID (also creates a same-named group)
addgroup -S GROUP && adduser -S -G GROUP USERCreate a system group and a system user in it
USER APPDockerfile instruction to drop root
dockerfile
FROM alpine:3.22
RUN adduser -D -u 10001 app
USER app

CA Certificates and Timezone #

COMMANDDESCRIPTION
apk add --no-cache ca-certificatesCA bundle at /etc/ssl/certs/ca-certificates.crt
update-ca-certificatesRebuild the bundle after adding .crt files to /usr/local/share/ca-certificates/
apk add --no-cache tzdataInstall zone data (not in the base image)
ln -sf /usr/share/zoneinfo/Europe/London /etc/localtimeSet the timezone (after installing tzdata)
-e TZ=Europe/LondonAlternative at docker run (needs tzdata; unverified)

Gotchas #

SYMPTOMCAUSE AND FIX
bash: not foundNo bash by default. Use sh, or apk add --no-cache bash
./binary: not found though the file existsUsually a glibc binary missing its loader. Alpine uses musl: use a musl build, compile on Alpine, or switch to Debian or Ubuntu
ldd --version prints musl libcConfirms musl
/bin/sh is BusyBox ashNo bashisms ([[ ]], arrays); lint with shellcheck -s sh
apk warns opening from cache ... No such fileHarmless when using --no-cache without an earlier apk update (seen on 3.22)
Python or Node packages compile from sourcePrebuilt manylinux wheels target glibc, so musl may need build tools (--virtual .build-deps) (unverified per package)
DNS behaves differently from glibcmusl has its own resolver; check the musl docs if lookups differ (unverified in detail)
Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.