Created
June 17, 2019 06:42
-
-
Save islander/2524465060cd125ab4086db25e8ed9e7 to your computer and use it in GitHub Desktop.
Add apt proxy to docker container
This file contains hidden or 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
#!/bin/bash -ex | |
# | |
# Add to your Dockerfile: | |
# | |
# RUN chmod +x add-apt-proxy.sh && ./add-apt-proxy.sh | |
# | |
# For additional information see: | |
# | |
# https://github.com/sameersbn/docker-apt-cacher-ng | |
# https://gist.github.com/dergachev/8441335 | |
CONFPATH=/etc/apt/apt.conf.d/01proxy | |
APT_PROXY_PORT=${1:-3142} | |
HOST_IP=$(awk '/^[a-z0-9]+\t00000000/ { printf("%d.%d.%d.%d\n", int("0x" substr($3, 7, 2)), int("0x" substr($3, 5, 2)), int("0x" substr($3, 3, 2)), int("0x" substr($3, 1, 2)));exit }' < /proc/net/route) | |
if [[ ! -z "$APT_PROXY_PORT" ]] && [[ ! -z "$HOST_IP" ]]; then | |
cat > $CONFPATH <<-EOL | |
Acquire::HTTP::Proxy "http://${HOST_IP}:${APT_PROXY_PORT}"; | |
Acquire::HTTPS::Proxy "false"; | |
EOL | |
cat $CONFPATH | |
echo "Using host's apt proxy." | |
else | |
echo "Not using apt proxy." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment