apk del: Usage, Options & Common CI Errors
apk del removes Alpine packages - most usefully an entire virtual build-dependency group.
apk del is the Alpine uninstall command. Its signature CI use is deleting a virtual package created at build time, which removes a whole group of build dependencies in one step to keep the image small.
What it does
apk del removes the named package (or virtual group) and any dependencies that are no longer needed. The idiomatic pattern is apk add --no-cache --virtual .build-deps <tools>, build, then apk del .build-deps - removing all the compilers and headers in a single command within the same Docker layer.
Common usage
apk add --no-cache --virtual .build-deps gcc musl-dev make
# ... compile the project ...
apk del .build-deps # remove the whole group
apk del curl # remove a single packageCommon errors in CI
For the image-slimming pattern to work, the apk add --virtual and apk del must run in the SAME Dockerfile RUN instruction (same layer) - split across layers, the deleted bytes still live in the earlier layer and the image does not shrink. "ERROR: No such package: .build-deps" means the virtual name does not match the one used at add time. Deleting a package that a runtime dependency still needs removes that dependency too - confirm the kept package list after a del.
Options
| Item | What it does |
|---|---|
| del <name> | Remove a package or virtual group |
| --virtual (on add) | Create the group del can remove at once |
| -r / --rdepends | Also remove reverse dependencies |