This uses two containers - one running apt-cacher-ng, and one running rawdns. In fact, this gist is mostly based on the apt-cacher-ng hack documented the rawdns repo.
This includes a few quirks for OS X, which I'll make note of.
- Edit ('create') /etc/rawdns.json to look like the
rawdns.jsonin this gist. - Run a rawdns container:
docker run -d --name rawdns -p 53:53/udp -v /var/run/docker.sock:/var/run/docker.sock -v /private/etc/rawdns.json:/etc/rawdns.json:ro tianon/rawdns rawdns /etc/rawdns.json. Note that this references /private/etc/rawdns.json; this is because on OS X, /etc is symlinked to /private/etc, and you can't mount a symlink. - Update your DNS resolver to use
127.0.0.1! Assuming OS X, this is in theNetworkpreference pane, behindAdvanced->DNS. dig dns.dockershould now includeSERVER: 127.0.0.1#53(127.0.0.1).- Run an apt-cacher-ng container:
docker run -d --name apt-cacher-ng --dns 8.8.8.8 --dns 8.8.4.4 tianon/apt-cacher-ng dig archive.ubuntu.comshould have aCNAME apt-cacher-ng.docker.entry. Note: as a bonus of running rawdns, all of your containers are now reachable atcontainer-name.docker.
Note: step 3 is no longer avoidable on OS X, because Docker for Mac doesn't let you specify a DNS server for the docker server. That might change in the future.