Skip to content
Latchkey

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

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

FlagWhat it does
--no-cacheFetch index, install, leave nothing cached
--virtual <name>Group build deps for one-step removal
--update-cache / -URefresh the index before installing
--no-progressCleaner 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: Build
  shell: bash
  run: |
    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.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card