Last active
December 26, 2015 13:43
-
-
Save wassname/6e97c2165d9ffe13b270 to your computer and use it in GitHub Desktop.
optional apt-get caching for docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aptcache: | |
image: sameersbn/apt-cacher-ng:latest | |
ports: | |
- "3142:3142" | |
volumes: | |
- /srv/docker/apt-cacher-ng:/var/cache/apt-cacher-ng | |
restart: always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# configure apt to not install reccomendations | |
ENV DEBIAN_FRONTEND noninteractive | |
RUN echo 'APT::Install-Recommends 0;' >> /etc/apt/apt.conf.d/01norecommends \ | |
&& echo 'APT::Install-Suggests 0;' >> /etc/apt/apt.conf.d/01norecommends | |
RUN apt-get update \ | |
&& apt-get install -y netcat \ | |
&& rm -rf /var/lib/apt/lists/* | |
# This uses the apt proxy only if present. It checks on port 3142 of the host/gateway, and returns DIRECT for no proxy, | |
# or the proxy address if it's detected. This uses an undocumented feature of apt-get. | |
# Ref: http://askubuntu.com/questions/53443/how-do-i-ignore-a-proxy-if-not-available | |
RUN export HOST_IP=$(ip route| awk '/^default/ {print $3}')\ | |
&& echo "#!/bin/bash" > /usr/local/bin/apt-ng-host-discover \ | |
&& echo "if nc -w1 -z $HOST_IP 3142; then printf http://$HOST_IP:3142; else printf DIRECT; fi" >> /usr/local/bin/apt-ng-host-discover \ | |
&& chmod +x /usr/local/bin/apt-ng-host-discover \ | |
&& echo 'Acquire::http::Proxy-Auto-Detect "/usr/local/bin/apt-ng-host-discover";' > /etc/apt/apt.conf.d/30proxy | |
# test it by running a verbose statement like this | |
apt-get -o Acquire::http::Proxy-Auto-Detect apt-get -o Acquire::http::Proxy-Auto-Detect download vim |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment