Speed up your docker builds using apt-cacher-ng

Speed up your docker builds using apt-cacher-ng

Install apt-cacher-ng on the host machine

sudo apt install apt-cacher-ng

Check if your apt-cacher-ng service is running by visiting localhost:3142 in your web browser

Check the ip your local docker0 interface

> ip a
....
5: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:60:c7:b6:6b brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:60ff:fec7:b66b/64 scope link 
       valid_lft forever preferred_lft forever
...

Provide the apt-cacher-ng service URL to your apt-based Dockerfile builds

In your Dockerfile builds use the proxy url for apt-cacher-ng by inserting this additional line

RUN echo 'Acquire::http { Proxy "http://172.17.0.1:3142"; };' >> /etc/apt/apt.conf.d/01proxy

This will work with any operating system base images whose repository system is supported by apt-cacher-ng. More details on apt-cacher-ng website

Subscribe to <site/>

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe