Is it necessary to RUN apk update && apk upgrade in a docker build stage?

Viewed 1421

I'm creating a multi stage build docker file. In the deployment step that will actually run the program i'm running

RUN apk update && apk upgrade --no-cache

Should I also have this statement in my build stage?

2 Answers

It isn't necessary to always apt update/upgrade in your dockerfile. However it surely isn't a bad idea. Especially if you install packages with apt, you should make sure that the package list is up-to-date. So you always get the latest version of the package you want to install.

Installing security updates on build time does matter, especially if your base image is not that recent. But I wouldn't call it necessary and it also depends on how important it is for your base image to be up-to-date.

Related