docker apt-get unable to locate package

The struggling Developer
2 min readJan 29, 2021



You have created your docker container and it runs happily. Suddenly problems arise in the software. You need to debug your application inside the docker container, but you didn´t install an editor.

You try apt-get install nano and all you get is “unable to locate package”. You try apt-get install vi. And apt-get install vim.

You even try apt-get install emacs.

But all the time the console just keeps telling you “unable to locate package”. “unable to locate package”. “unable to locate package”



Execute a simple apt-get update before you execute your installation command, like apt-get install nano (yes I prefer nano) and see it being successfully being installed in the running instances of your docker container (remember this, after a container restart your editor is gone again).


apt needs to know which packages exist, in which version and if they are available for the current version of the distribution.

When you receive “unable to locate package” from apt-get, that means you are using a more stripped down version of a debian or ubuntu based distribution.

The command apt-get update retrieves the live data and creates the cache required.


Docker images come in different variants, some stripped down to the bare minimum (often highly specialized images e.g. to run only redis). Other images seem to be fully blown Installation of operating systems (self hosting online development work spaces).

Production level Debian or Ubuntu based docker images remove the cache and any not required data to reduce the image size. Normally you don´t need to install anything else after the finished docker image is at hand.

But apt requires the cache. Therefore you need to help it retrieve the data and create the cache.

After you experienced this a few times you probably want to change your Dockerfile and make sure to install the tools you regularly require. Nobody is perfect, mistakes happen. And having for example a text editor inside your image can help you quickly debug problems and try out solutions within the real environment.

Let me know when it helped.




First appeared on