Sorry, very new to server stuff, but very curious. Why run apt-get update when building a container?
My guess would be that it's for security purposes, if that the case than that'll answer the question.
apt-get update
ensures all package sources and dependencies are at their latest version, it does not update existing packages that have been installed. It's recommended that you always run apt-get update
prior to running an apt-get install
this is so when the apt-get install
is run, the latest version of the package should be used.
RUN apt-get update -q -y && apt-get install -q -y <your-program>
(the -q -y flags just mean that the apt process will run quietly without asking you for confirmations as this would cause the Docker process to fail)
First, lets make a distinction between apt-get update
and apt-get upgrade
. The update
is to get the latest package index. This is so that you don't run into errors for outdated or redacted packages when doing a apt-get install
.
The upgrade
is actually going through an upgrading packages. It usually also requires a preceding update
to have the updated package index. This might be done if there are package or security concerns of already installed packages.
You usually see an update
a lot in builds because the base image may have a fairly out of date package index and just doing an apt-get install
can fail.
The upgrade
would be less common. But could still be done if you want to ensure the latest packages are installed.