apk add --no-cache: Usage, Options & Common CI Errors
By Daniel Zoghalchali·Latchkey
--no-cache installs Alpine packages while leaving no package index behind in the image.
apk add --no-cache is the canonical one-liner for Alpine Docker images: it fetches a fresh index, installs, and discards the index in a single step - no separate apk update and no cache to clean up.
What it does
Without --no-cache, apk caches the package index under /var/cache/apk, which you then have to delete to keep the image small. --no-cache fetches the index, uses it for this install, and does not write it to disk - equivalent to apk update + install + rm of the cache, but in one atomic step.
Common usage
Terminal
apk add --no-cache curl # the standard idiom
RUN apk add --no-cache python3 py3-pip # in a Dockerfile
apk add --no-cache --virtual .build gcc musl-dev && apk del .build
Common errors in CI
If you omit --no-cache and forget to clean up, the image carries the /var/cache/apk index for no benefit. The reverse trap: a script that runs apk add (no flag) without a prior apk update on a base whose index is stale fails with "no such package" - --no-cache avoids that because it always pulls a current index. Pinning an exact version under --no-cache can still hit "unsatisfiable constraints" once Alpine prunes that version from the repo.
Options
Flag
What it does
--no-cache
Fetch index, install, leave nothing cached
--virtual <name>
Group build deps for one-step removal
--update-cache / -U
Refresh the index before installing
--no-progress
Cleaner CI logs
Using this in CI
A runner shell is not a login shell. It does not read your dotfiles, it usually has no TTY, and by default it does not stop on the first error, so a failing command in the middle of a multi-line run block can leave the job green.
.github/workflows/ci.yml
# make the shell behave the way you assume it does- name:Buildshell:bashrun:|set -euo pipefail # exit on error, undefined vars, and pipeline failures./do-the-thing | tee out.log
Frequently asked questions
apk add --no-cache: Usage, Options & Common CI Errors?
apk add --no-cache is the canonical one-liner for Alpine Docker images: it fetches a fresh index, installs, and discards the index in a single step - no separate apk update and no cache to clean up.
What it does?
Without --no-cache, apk caches the package index under /var/cache/apk, which you then have to delete to keep the image small. --no-cache fetches the index, uses it for this install, and does not write it to disk - equivalent to apk update + install + rm of the cache, but in one atomic step.
Common errors in CI?
If you omit --no-cache and forget to clean up, the image carries the /var/cache/apk index for no benefit. The reverse trap: a script that runs apk add (no flag) without a prior apk update on a base whose index is stale fails with "no such package" - --no-cache avoids that because it always pulls a current index.