If you're finding your
apt-get install (or equivalent) commands fail when building Docker images, but you've successfully tested the flow you have in your Dockerfile elsewhere, it could be a Docker caching issue.
apt-get update (or equivalent) in one RUN command (Docker layer) and then
apt-get install is executed in another RUN command you can run into these package install failures. Docker attempts to use cached layers as much as possible. It's possible for Docker to use an older, cached layer where
apt-get update was previously run and for your
apt-get install command to be being executed without the latest package list available. The result is that the package manager can't find the package you're trying to install and this step will fail (or potentially cause the wrong version to be installed).
To get around this issue, it's best to bundle your package manager commands into a single RUN command.
Instead of doing something like this:
RUN apt-get -y update RUN apt-get -y install python-pil
RUN apt-get -y update && \ apt-get -y install python-pil
This will put both steps into the one layer, so your 'install' command is always executed with a fresh package list.