If you ever run into such error below when building your Docker image…
It’s likely you had these as separated lines in your Dockerfile (before
apt-get install commands):
You should instead combine them in a single line, for example:
Here is why:
- By default, Docker cache your commands to reduce time spent building images. Unless there was any change before such commands (or at the same line).
- Linux distros are updated regularly, and it requires you to run
apt-get updatefrequently otherwise
apt-get installmight not works as intended.
So, if you have built the image earlier (with a linux distro that recently had some updates), and you want to add some more libraries, for example:
apt-get update command will get bypassed since it’s already get cached, your package management (i.e
apt-get) would not be up-to-date while you thought it should always be.
After a few search, I found this issue on Docker repo: https://github.com/docker/docker/issues/1996 too bad it’s closed because there were not many real world use cases - they might be right though. Of course, we can always use
--no-cache=true as an option for our
docker build command, but it will build everything all over again everytime - you probably don’t want that.
Anyway, below are some few links that I find useful for my Docker use:
And that should be it.