Should I Add Package Updates to My Dockerfile?

0
3
Asked By PineappleNinja42 On

Hey everyone! I have a quick question about my Dockerfile. Should I include these lines to update my packages? If not, could you explain why?

RUN apt update && apt upgrade -y
RUN apt clean && apt autopurge -y

Thanks for your input!

2 Answers

Answered By QuickDrawMcGraw1 On

You definitely should if you want to have newer versions of system packages than what your base image provides. Just a heads up, if you're working with a Debian/Ubuntu image, you use 'apt', whereas for Alpine-based images, you'd use 'apk'. Also, it's better to combine those commands into a single RUN command, separated by '&&', to keep your image smaller by avoiding extra cache layers.

TechieTim111 -

But I've seen advice suggesting that you shouldn't upgrade packages in the Dockerfile. If you rebuild your image, you lose the previous state of the system, which might cause some issues.

Answered By ContainerCrafter99 On

Doesn't Docker cache those RUN commands after they're executed? So even if new packages are available later, that command would just be pulled from the cache, right? You'd actually need to update the base image itself to get newer dependencies instead.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.