{"id":100,"date":"2020-01-28T01:30:21","date_gmt":"2020-01-28T01:30:21","guid":{"rendered":"https:\/\/www.vandervecken.com\/faucet\/?p=100"},"modified":"2020-01-28T01:30:21","modified_gmt":"2020-01-28T01:30:21","slug":"making-docker-applications-build-faster-caching-packages","status":"publish","type":"post","link":"https:\/\/faucet.vandervecken.com\/index.php\/2020\/01\/28\/making-docker-applications-build-faster-caching-packages\/","title":{"rendered":"making docker applications build faster &#8211; caching packages"},"content":{"rendered":"\n<p>If you&#8217;re like me &#8211; you live in the middle of nowhere, in New Zealand, without fiber let alone any DSL, and you develop a lot of software using docker &#8211; you might find your build\/deploy cycle a bit painful, since many docker builds download packages.<\/p>\n\n\n\n<p>Even if you are an unusual case &#8211; you live in an urban area with good espresso on every corner, scarce parking, and fiber to the couch (complete with 5G) &#8211; retrieving lots of packages from disk\/SSD is still faster than fiber.<\/p>\n\n\n\n<p>Running a <a href=\"https:\/\/docs.docker.com\/registry\/recipes\/mirror\/\">docker pull through cache<\/a> can help if you have a few machines pulling the same images. However, you sometimes you still need to actually build those images locally, and the build process can involve a lot of apt-get&#8217;ing or apk add&#8217;ing.<\/p>\n\n\n\n<p>To help with package retrieval over HTTP, you can run <a href=\"https:\/\/docs.docker.com\/engine\/examples\/apt-cacher-ng\/\">apt-cacher-ng<\/a>. That&#8217;s great if you have a way to convince your docker build to use the cache (e.g. via an environment variable). However it&#8217;d be even nicer not to have to do anything special.<\/p>\n\n\n\n<p>The missing piece in the puzzle, is a transparent HTTP proxy (like squid), that knows how to redirect requests to apt-cacher-ng. This is what I do and it makes docker builds really fast (at least, the package retrieval part). Using a relatively old squid redirector, <a href=\"http:\/\/www.linofee.org\/~jel\/webtools\/jesred\/\">jesred<\/a>, squid intercepts common package retrieval URLs and pass them to apt-cacher-ng.<\/p>\n\n\n\n<p>Here&#8217;s part of my \/etc\/jesred.conf:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>regex ^http:\/\/((.*)archive.ubuntu.com\/ubuntu\/(dists|pool)\/.*)$    http:\/\/localho\nst:3142\/\\1\nregex ^http:\/\/(security.ubuntu.com\/ubuntu\/(dists|pool)\/.*)$    http:\/\/localhost:\n3142\/\\1\nregex ^http:\/\/(dl-cdn.alpinelinux.org\/alpine.+)$    http:\/\/localhost:3142\/\\1\nregex ^http:\/\/(.*cdn.*.debian.org\/.+)$\thttp:\/\/localhost:3142\/\\1\nregex ^http:\/\/(deb.debian.org\/.+)$  http:\/\/localhost:3142\/\\1\nregex ^http:\/\/(archive.raspberrypi.org\/debian\/.+)$    http:\/\/localhost:3142\/\\1\n<\/code><\/pre>\n\n\n\n<p>Of course, your squid installation has to be set up to do transparent caching on port 80, and has to reference jesred in \/etc\/squid\/squid.conf:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redirect_program \/usr\/lib\/squid\/jesred<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re like me &#8211; you live in the middle of nowhere, in New Zealand, without fiber let alone any DSL, and you develop a lot of software using docker &#8211; you might find your build\/deploy cycle a bit painful, since many docker builds download packages. Even if you are an unusual case &#8211; you &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/faucet.vandervecken.com\/index.php\/2020\/01\/28\/making-docker-applications-build-faster-caching-packages\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;making docker applications build faster &#8211; caching packages&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-uncategorised","entry"],"_links":{"self":[{"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/posts\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/comments?post=100"}],"version-history":[{"count":1,"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":101,"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/posts\/100\/revisions\/101"}],"wp:attachment":[{"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/media?parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/categories?post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/tags?post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}