Skip to content

Developing With Docker (Day 2), caching debs using squid-deb-proxy

Today’s step is going to take a bit of a detour. One of the things that kills you when rebuilding a box is that you have to download dependencies every time from the internet. With big files this can be quite slow, and can keep you from working at all if you are offline.

So I’m going try and cache as many of these files on my host box as possible so this isn’t an issue. Of course if I add new dependencies and I’m offline, it won’t work unless I’ve somehow cached them before. But I should be able to rebuild the machine.

So if you pull down the repo, there will be a tag for Day 2.

Diff of the changes from day1 to day2 (git diff day1 day 2)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..909475b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
diff --git a/Dockerfile b/Dockerfile
index d643899..641429e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,9 @@
 from ubuntu:12.10
+# set your host up as the apt cache for speed
+add 30proxy /etc/apt/apt.conf.d/30proxy
 # update system and install dependencies
 run apt-get update
diff --git a/ b/
new file mode 100755
index 0000000..45754e8
--- /dev/null
+++ b/
@@ -0,0 +1,3 @@
+sudo apt-get install squid-deb-proxy
+HOST_IP=`ifconfig docker0 |grep inet|head -1|sed 's/\:/ /'|awk '{print $3}'`
+echo "Acquire::http::Proxy \"http://$HOST_IP:8000\";" > 30proxy
\ No newline at end of file
diff --git a/ b/
new file mode 100755
index 0000000..50a0f87
--- /dev/null
+++ b/
@@ -0,0 +1,2 @@
+#! /bin/bash
+docker run -i -t u1210_nodebase /bin/bash
\ No newline at end of file

* Ignore 30proxy which is a generated file so we don’t check it in accidentally
* In the Dockerfile, tell docker to copy the 30proxy file over to /etc/apt/apt.conf.d/30proxy, so that it’ll configure apt.
* Create a script which you can (and should) run to install squid-deb-proxy to your host and correctly configure the container to point at the host for it’s apt cache.
* Add a script which makes it easier to shell into this instance.


So we can see this is working by opening a second terminal window and doing a “tail -f /var/log/squid-deb-proxy/access.log”.

And then running in the original terminal. You should see lines like:
1375291602.249 2235 TCP_MISS/200 861368 GET – DIRECT/ application/x-debian-package

Which means a cache miss, and a fetch from the real source (TCP_MISS). Or lines like this:
1375295650.284 4 TCP_MEM_HIT/200 202735 GET – NONE/- application/x-debian-package

Which means squid served the file from memory (no external network access).

That’s about it. Tomorrow we’ll get back into

One Comment

  1. WordPress › Error

    There has been a critical error on this website.

    Learn more about troubleshooting WordPress.