If I run sudo apt-get update inside docker image and run it as a container, do I still need to sudo apt-get update on the machine too? I'm still trying to wrap my head around how exactly Docker works because one part of my brain is telling me that everything running in the Docker container relies on everything inside the Docker container itself so it's not necessary to sudo apt-get update on the machine too and another part of my brain is telling me that's not right so I'm pretty confused now.
2 Answers
Whenever you run apt-get update
in docker container
or inside your Dockerfile
It is actually create it's own isolated space which will run all the command in that particular space only without affecting your physical server/environments only container and your physical server/environments is sharing same kernel
. So if you run apt-get update
or any other command than it will just run in docker container or docker image you are creating.
I would strongly recommend you to read this answer for your understanding about docker. docker and virtual machine
Hope this will help you!
Thank you!

- 1,440
- 1
- 15
- 25
Those dependencies are not that hard connected to your docker host as you might expect (as long as you do not mount any volumes to it).
You can verify your suggestion with few lines of code. Let's use the plain ubuntu image:
docker run --rm ubuntu apt-get install git
Which results in E: Unable to locate package git
. This is because the packages have never been updated with apt-get update
.
If we supply a Dockerfile consisting of these few lines:
FROM ubuntu
RUN apt-get update
and build it to get a new image
docker build -t myubuntu .
we can execute the new image like this
docker run --rm myubuntu apt-get install git
which then tries to install git from the official repositories, because the image previously has executed apt-get update
.
However, I'd not suggest to rely in the container that the image has outdated via apt-get
.

- 6,175
- 3
- 28
- 46