-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure-docker-proxy.sh
executable file
·52 lines (38 loc) · 1.22 KB
/
configure-docker-proxy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
#
# this script automate configuration of the HTTP_PROXY into docker
#
# see documentation for docker with systemd
# https://docs.docker.com/engine/articles/systemd/
#
# this script must be run as privileged user
if [ $(id -u) -ne 0 ] ; then
echo "Error : this script requires sudo"
exit 16
fi
set -e
if test $# -ne 2
then
echo "Invalid number of parameters : usage : $0 <proxy_host> <proxy_port>"
exit 1
fi
PROXY_HOST=$1
PROXY_PORT=$2
echo "Will use http://${PROXY_HOST}:${PROXY_PORT} as the proxy to use with docker"
# create a systemd drop-in directory for the docker service
mkdir -p /etc/systemd/system/docker.service.d/
# Now create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable
cat << EOF > /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://${PROXY_HOST}:${PROXY_PORT}/" "NO_PROXY=localhost,127.0.0.1"
EOF
# Flush changes
sudo systemctl daemon-reload
# Verify that the configuration has been loaded
sudo systemctl show docker --property Environment
# Restart Docker
systemctl restart docker
# pulling the busybox image in order to test everything is fine
docker pull busybox
echo "Done"
exit 0