Skip to content

Instantly share code, notes, and snippets.

@ismith
Last active November 12, 2016 21:56
Show Gist options
  • Save ismith/958e1c647a05ebd22763fb246a6f910e to your computer and use it in GitHub Desktop.
Save ismith/958e1c647a05ebd22763fb246a6f910e to your computer and use it in GitHub Desktop.
Local apt repo cache using docker

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.

  1. Edit ('create') /etc/rawdns.json to look like the rawdns.json in this gist.
  2. 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.
  3. Update your DNS resolver to use 127.0.0.1! Assuming OS X, this is in the Network preference pane, behind Advanced -> DNS.
  4. dig dns.docker should now include SERVER: 127.0.0.1#53(127.0.0.1).
  5. 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
  6. dig archive.ubuntu.com should have a CNAME apt-cacher-ng.docker. entry. Note: as a bonus of running rawdns, all of your containers are now reachable at container-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.

{
"httpredir.debian.org.": {
"type": "static",
"cnames": [ "apt-cacher-ng.docker" ],
"nameservers": [ "127.0.0.1" ]
},
"archive.ubuntu.com.": {
"type": "static",
"cnames": [ "apt-cacher-ng.docker" ],
"nameservers": [ "127.0.0.1" ]
},
"docker.": {
"type": "containers",
"socket": "unix:///var/run/docker.sock"
},
"local.": {
"type": "forwarding",
"nameservers": [ "192.168.1.1" ]
},
".": {
"type": "forwarding",
"nameservers": [ "8.8.8.8", "8.8.4.4" ]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment