Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

would dockerfile apt-get cache cause nonidentical docker container?

Tags:

docker

I am reading dockerfile documentation.
I saw it mention the dockerfile would utilize cache better to improve build process.
So the documentation recommend that if you try to RUN apt-get update, merge the command to the following package install such as RUN apt-get update && apt-get install curl to avoid installing out-date package due to the cache.

I am wondering what if I download the same dockerfile but I build the docker image at different computers at different time. Because the local cache in each computer, they still have chance to build different docker container even they run the same dockerfile.

I haven't encountered this problem. Just wonder is this possible and how to prevent it?

Thanks.

like image 883
鄭元傑 Avatar asked Nov 07 '25 04:11

鄭元傑


1 Answers

Debian APT repositories are external resources that change regularly, so if you docker build on a different machine (or repeat a docker build --no-cache on the same machine) you can get different package versions.

On the one hand, this is hard to avoid. Both the Debian and Ubuntu repositories promptly delete old versions of packages: the reason to apt-get update and install in the same RUN command is that yesterday's package index can reference package files that no longer exist in today's repository. In principle you could work around this by manually downloading every .deb file you need and manually dpkg --install them, skipping the networked APT layer.

On the other, this usually doesn't matter. Once you're using a released version of Debian or Ubuntu, package updates tend to be limited to security updates and bug fixes; you won't get a different major version of a package on one system vs. another. This isn't something I've seen raised as an issue, except that having a cached apt-get update layer can cause you to miss a security update you might have wanted.

like image 122
David Maze Avatar answered Nov 09 '25 00:11

David Maze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!