forked from hugojosefson/ubuntu-install-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-docker-behind-proxy
executable file
·66 lines (50 loc) · 2.4 KB
/
install-docker-behind-proxy
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
set -e
. /etc/lsb-release
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo sh -c "echo deb https://apt.dockerproject.org/repo ubuntu-$DISTRIB_CODENAME main > /etc/apt/sources.list.d/docker.list"
which aptitude || sudo apt-get install -y aptitude
sudo aptitude install -y apt-transport-https ca-certificates
sudo aptitude update
sudo aptitude install -y docker-engine cgroup-lite
sudo gpasswd -a ${USER} docker
PROXY=${PROXY:-localhost:3128}
PROXY_HOST=${PROXY_HOST:-${PROXY%%:*}}
PROXY_PORT=${PROXY_PORT:-${PROXY#*:}}
PROXY=$PROXY_HOST:$PROXY_PORT
DNS=${DNS:-$(nmcli device show | awk -F ' ' '/^IP4.DNS/{print $2}'| xargs echo | sed -r 's/(^| )/ --dns=/g')}
EXEC_START=${EXEC_START:-$(cat /lib/systemd/system/docker.service | grep ExecStart)$DNS}
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf >/dev/null <<EOF
[Service]
Environment="HTTP_PROXY=http://$PROXY/" "HTTPS_PROXY=http://$PROXY/" "http_proxy=http://$PROXY/" "https_proxy=http://$PROXY/"
ExecStart=
$EXEC_START
EOF
sudo systemctl daemon-reload
sudo systemctl stop docker
sudo systemctl start docker
sleep 2
sudo su - $USER -c "docker run hello-world"
EXISTING_REDSOCKS=$(sudo su - $USER -c "docker ps" | grep ncarlier/redsocks | awk '{print $1}')
if [[ -n "$EXISTING_REDSOCKS" ]]; then
for i in $EXISTING_REDSOCKS; do
sudo su - $USER -c "docker stop $i > /dev/null"
sudo su - $USER -c "docker rm -f $i > /dev/null"
done
fi
sudo su - $USER -c "docker run --restart=always --privileged=true --net=host -d ncarlier/redsocks $PROXY_HOST $PROXY_PORT > /dev/null"
mkdir -p ~/bin
curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` > ~/bin/docker-compose
chmod +x ~/bin/docker-compose
sudo sh -c "curl -L https://raw.githubusercontent.com/docker/compose/1.8.0/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose"
cd $(mktemp -d)
git clone https://gist.github.com/76b450a0c986e576e98b.git
cd 76b450a0c986e576e98b
mv docker-cleanup ~/bin/
chmod +x ~/bin/docker-cleanup
echo "Installed and configured docker to go through the proxy $PROXY."
echo " /etc/systemd/system/docker.service.d/http-proxy.conf"
echo " ~/bin/docker-compose"
echo " ~/bin/docker-cleanup"
echo " $(sudo su - $USER -c "docker ps" | grep ncarlier/redsocks)"