-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker_proxy.sh
executable file
·50 lines (44 loc) · 1.26 KB
/
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
#!/bin/bash
set -e
# defaults
domain=
proxy_host=localhost
proxy_port=3128
proxy_user=
# load from configuration
test -f config && . config
FORWARD_TO_PROXY="PREROUTING -i docker0 -p tcp --dport 80 -j REDIRECT --to 33128 -m comment --comment 'DOCKER_PROXY'"
case "$1" in
start)
read -p "Proxy host: ($proxy_host) " input && proxy_host="${input:-$proxy_host}"
read -p "Proxy port: ($proxy_port) " input && proxy_port="${input:-$proxy_port}"
read -p "$proxy_host:$proxy_port username: ($proxy_user) " input && proxy_user="${input:-$proxy_user}"
read -s -p "$proxy_user@$proxy_host:$proxy_port password: " proxy_pass && echo
docker run --name docker-proxy -d -p 33128:3128 \
-e username=$proxy_user \
-e domain=$domain \
-e password=$proxy_pass \
-e proxy=$proxy_host:$proxy_port \
kops/docker-proxy-relay:2.0
sudo iptables -t nat -A $FORWARD_TO_PROXY
sudo iptables -t nat -L -n
;;
stop)
sudo iptables -t nat -D $FORWARD_TO_PROXY
sudo iptables -t nat -L -n
docker stop docker-proxy || docker kill docker-proxy
docker rm docker-proxy
;;
status)
docker ps | head -1
docker ps | grep docker-proxy
sudo iptables -t nat -L -n | grep "DOCKER PROXY"
;;
*)
cat <<EOF
Usage: $0 start
$0 stop
$0 status
EOF
;;
esac