dnf makecache: Prebuild the Metadata Cache
dnf makecache downloads and builds the repository metadata so later install commands do not pause to fetch it.
Prebuilding the cache is useful in Docker layers and to surface a broken repo early. It also pairs with dnf clean all to control image size.
What it does
dnf makecache fetches the metadata (repomd.xml, primary, filelists) for each enabled repository and stores it under /var/cache/dnf. Subsequent install and search commands then use the cache instead of downloading metadata again.
Common usage
dnf makecache
# force a refresh even if the cache looks current
dnf makecache --refresh
# clean it out afterward to shrink the image
dnf clean all && rm -rf /var/cache/dnfOptions
| Command / Flag | What it does |
|---|---|
| dnf makecache | Download and build the metadata cache |
| --refresh | Refresh even if metadata is within its expiry |
| --timer | Run in the low-priority background mode |
| dnf clean all | Remove all cached metadata and packages |
| dnf clean metadata | Remove only cached metadata |
In CI
Run dnf makecache early in a Dockerfile so a broken or slow repo fails fast, then dnf clean all in the final install layer so the cache does not bloat the image. --refresh forces a fresh pull when you suspect stale metadata.
Common errors in CI
"Failed to download metadata for repo '<id>': Cannot download repomd.xml" means the repo URL is unreachable or the mirror is down. "Status code: 404 for <url>" means the release version in the repo path no longer exists. "GPG key retrieval failed" or "Public key ... is not installed" means the repo GPG key is missing; import it with rpm --import.