Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preserve apt-cache archive directory when using docker / host volumes

The use case is fairly straightforward. I am dockerizing our local provisioning (which utilizes chef to configure our ubuntu servers). I am using a few data volumes to share host directories that I want as a cache for the docker containers: eg:

docker run -d -P -h docker -v /foo/apt-cache:/var/cache/apt/archives foo:base

However, the debian package files in /var/cache/apt/archives directory keep getting blown out after each package install. Can someone point me to where this happens in docker and a workaround, so I can preserve my apt-get cache nicely across containers?

Thanks in advance

like image 541
Christopher Kuttruff Avatar asked Jun 23 '14 18:06

Christopher Kuttruff


People also ask

Where is Docker build cache stored?

The cache uses the same storage driver as used for image layers. Metadata is stored in databases at /var/lib/docker/buildkit .

What is apt cacher ng?

Apt-Cache-ng is A caching proxy. Specialized for package files from Linux distributors, primarily for Debian (and Debian based) distributions but not limited to those. A caching proxy have the following benefits: Lower latency. Reduce WAN traffic.

Does Docker have cache?

Docker uses a layer cache to optimize and speed up the process of building Docker images. Docker Layer Caching mainly works on the RUN , COPY and ADD commands, which will be explained in more detail next.

What is Docker layer caching?

With Docker layer caching, you can save individual layers of the Docker images you build so that they can be reused in subsequent pipeline runs. Docker layer caching can save your team significant time during the build process by bypassing some or all of the image build steps.


1 Answers

sharing /var/cache/apt/archives seems a fragile solution. Maybe you should give a try to setting up a container running apt-cacher-ng and configure apt on your other containers to use that proxy.

Docker has an article explaining how to set this up.

like image 129
Thomasleveil Avatar answered Oct 02 '22 11:10

Thomasleveil