-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquid-in-a-can
executable file
·76 lines (68 loc) · 2.11 KB
/
squid-in-a-can
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
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
set -e
# Run a Squid caching proxy with Docker (as a daemon).
# The container it's based on (chrisdaish/squid) is about 18MB.
#
# To customize the Squid configuration on start up, just create a
# file 'squid.conf' or pass one via the SQUID_CONF environment variable.
# The squid.conf.example file in this directory should work.
# load .env variables
[ -r .env ] && . ./.env
_usage () {
printf "Usage: $0 [OPTIONS]
This script runs a Squid proxy in a background Docker container.
Options:
-f FILE The FULL path to a Squid config file
-c NAME Name of a persistent Docker volume for the squid cache
-C DIR The path to the certs/ directory to volume-map in
-s NAME Name of a persistent Docker volume for the SSL cert database
-h This screen
"
exit 1
}
while getopts "f:c:C:s:h" args ; do
case $args in
f)
SQUID_CONF="-v $OPTARG:/etc/squid/squid.conf:ro"; shift 2 ;;
c)
SQUID_VOL="-v $OPTARG:/var/cache/squid"; shift 2 ;;
C)
SQUID_CERT="-v $OPTARG:/etc/squid/certs"; shift 2 ;;
s)
SQUID_SSLDB="-v $OPTARG:/var/lib/ssl_db"; shift 2 ;;
\?)
echo "unknown $arg - $OPTARG" ; _usage ;;
h|help)
_usage ;;
*)
echo "error: invalid arg $arg - $OPTARG" ; exit 1 ;;
esac
done
if [ $# -gt 0 ] ; then
echo "$0: Error: unexpected arguments"
_usage
fi
set -x
docker run \
--rm \
-d \
--hostname "squidcache" \
--name "squidcache" \
$SQUID_CONF \
$SQUID_VOL \
$SQUID_CERT \
-v /etc/localtime:/etc/localtime:ro \
-p 3128:3128 \
-p 3132:3132 \
"$DOCKER_IMG" \
"$@"
# For an intercepting proxy:
#
# * Create a valid squid config, and pass it in the above command like this:
# -v /etc/squid/squid.conf:/etc/squid/squid.conf:ro \
#
# * Add '--net=host' in the above command
#
# * Make sure your squid host has forwarding and redirect enabled:
# ./linux-network.sh ip-forward enable
# ./linux-network.sh iptables-redirect enable