2

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.

jkris
  • 4,851
  • 1
  • 21
  • 29

2 Answers2

2

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)

TheStoneFox
  • 2,917
  • 3
  • 29
  • 46
2

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.

Andy Shinn
  • 23,476
  • 6
  • 70
  • 90