apk add --no-cache: Usage, Options & Common CI Errors
--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
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 .buildCommon 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 |