Founding prices until 15 December: 30% off Pro, locked for life. See pricing

$ … E: Unable to locate package

Dockerfile 'Unable to locate package': apt-get update and the build cache

apt-get install runs with a stale or empty package list.

Docker

What it means

Base images ship without apt package lists. If apt-get update is in its own RUN line, Docker caches that layer and later builds install from a months-old list, or the name is wrong for that distribution release.

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. apt-get update cached in a separate layer (or missing)

Check:

grep -n apt-get Dockerfile

Fix: RUN apt-get update && apt-get install -y --no-install-recommends pkg && rm -rf /var/lib/apt/lists/* in one RUN.

2. The package name differs on this distribution or release

Check:

docker run --rm <base> sh -c 'apt-get update -qq && apt-cache search <name>'

Fix: Use the name for that release, or pin a base image that has it.

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.