Docker Build "apk add" Network Failure in CI
An apk add inside an Alpine build could not reach the package mirrors. The fetch fails with a temporary/network error - DNS, a flaky mirror, or no outbound network for that build step.
What this error means
A RUN apk add ... step fails with temporary error (try again later), Could not connect to ... dl-cdn.alpinelinux.org, or fetch ... failed. The same Dockerfile builds fine when the network is healthy.
#6 1.20 fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/main/x86_64/APKINDEX.tar.gz
#6 1.45 ERROR: unable to select packages:
#6 1.45 temporary error (try again later)Common causes
A flaky or slow Alpine mirror
The CDN mirror can briefly fail or time out, so the index fetch (and thus package selection) fails. This is usually transient.
DNS resolution failing in the build
If the builder cannot resolve dl-cdn.alpinelinux.org, every fetch fails before it even connects.
No outbound network for the step
A --network=none step, or a runner with restricted egress, leaves apk with nothing to fetch.
How to fix it
Update the index and retry within the step
Refresh the index and let the package manager retry the fetch.
RUN apk update && apk add --no-cache ca-certificates curlConfirm egress and DNS for the build
Make sure the build step has network and can resolve the mirror.
How to prevent it
- Use
apk add --no-cacheand keep package lists minimal. - Ensure the build step has outbound network and working DNS.
- Consider a pinned internal mirror for high-volume CI.