Last active
April 15, 2022 19:04
-
-
Save am3n/235272ed9f8967a07b55be93209f4991 to your computer and use it in GitHub Desktop.
Set docker http-proxy
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
#!/bin/bash | |
# Also in case you want to add a socks proxy, you might want to add this instead: ALL_PROXY=socks5://<host>:<port> | |
HOST="$1" | |
PORT="$2" | |
if test -z "$HOST" | |
then | |
echo "First arg is the proxy host name & is NULL"; exit; | |
fi | |
if test -z "$PORT" | |
then | |
echo "Second arg is the proxy port number & is NULL"; exit; | |
fi | |
mkdir -p /etc/systemd/system/docker.service.d/ | |
cd /etc/systemd/system/docker.service.d/ | |
touch http-proxy.conf | |
echo "[Service]" > http-proxy.conf | |
echo "Environment=\"HTTP_PROXY=http://$HOST:$PORT\"" >> http-proxy.conf | |
echo "Environment=\"HTTPS_PROXY=http://$HOST:$PORT\"" >> http-proxy.conf | |
echo "Environment=\"NO_PROXY=localhost,127.0.0.0/8,docker-registry.somecorporation.com\"" >> http-proxy.conf | |
sudo systemctl daemon-reload | |
printf "\nDocker environments:\n" | |
echo " "$(sudo systemctl show --property Environment docker) | |
echo " " | |
while true; do | |
read -p "Restart docker to use proxies? (y: restart now) (n: later) " yn | |
case $yn in | |
[Yy]* ) sudo systemctl restart docker; break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment