Last active
July 19, 2017 08:51
-
-
Save swdream/350a02699282b656062bd381c6e6b666 to your computer and use it in GitHub Desktop.
Problem when configuring cache_dir for squid proxy
This file contains hidden or 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
1. requirement: setup squid proxy server using docker. | |
2. The problem: cannot configure cache_dir for squid. | |
3. More detail: | |
- I tried some docker image to setup squid: | |
https://hub.docker.com/r/babim/squid/ (babin/squid:auth) | |
https://hub.docker.com/r/scbunn/squid/ (scbunn/squid:3.5.17) | |
all of them work fine when I DON'T CONFIGURE CACHE_DIR for squid. | |
but when I configure CACHE_DIR, the squid process was killed immediately after starting. | |
Then I decided to create my own image to be easy develop and maintain as I understand all about it. | |
I created a docker image here: https://hub.docker.com/r/swdream/squid/ | |
Github repo: https://github.com/swdream/squid | |
but I got the same problem: | |
when I configure CACHE_DIR, the squid process was killed immediately after starting | |
https://github.com/swdream/squid/blob/master/conf/squid.conf#L27 | |
with no error log is printed out: | |
``` | |
thanhnguyen@thanhnguyen:~/github/squid$ docker run --name squid -p 3128:3128 -e USERNAME=foo -e PASSWORD=bar -v /data/cache:/var/cache/squid swdream/squid:3.5.23 | |
thanhnguyen@thanhnguyen:~/github/squid$ docker ps -a | grep squid | |
996dfbc71f94 swdream/squid:3.5.23 "/entrypoint.sh squid" 8 seconds ago Exited (1) 7 seconds ago squid | |
... | |
thanhnguyen@thanhnguyen:~/github/squid$ docker logs 996dfbc71f94 | |
Adding password for user foo | |
Staring squid [3.5.23] | |
``` | |
4. How to reproduce: | |
In your machine, run this docker command to use my image swdream/squid:3.5.23 | |
``` | |
$ docker run --name squid -p 3128:3128 -e USERNAME=foo -e PASSWORD=bar -v /data/cache:/var/cache/squid swdream/squid:3.5.23 | |
``` | |
then, cannot start squid container and squid process will be killed immediately after starting with no error log found. | |
5. What I did: | |
- add some checks to make sure all necessary directories are already existed before stating squid and they have right owner. | |
https://github.com/swdream/squid/blob/68835126c3a82370d6edf85036f1482f984b5553/entrypoint.sh#L15 | |
https://github.com/swdream/squid/blob/68835126c3a82370d6edf85036f1482f984b5553/entrypoint.sh#L24 | |
https://github.com/swdream/squid/blob/68835126c3a82370d6edf85036f1482f984b5553/entrypoint.sh#L38 | |
- make sure start squid process with right user: | |
https://github.com/swdream/squid/commit/1bedce2cab448a75969f67f29adebbd34cf3f88c | |
- Run manually all my commands in Dockerfile and entrypoint in a alpine 3.3 container (my image is based on alpine:3.3) | |
and squid worked find with the same config file. | |
https://github.com/swdream/squid/blob/master/conf/squid.conf#L27 | |
``` | |
/ # ps -ef | grep squid | |
112 root 0:00 /usr/sbin/squid | |
114 squid 0:01 {squid} (squid-1) | |
115 squid 0:00 {log_file_daemon} (logfile-daemon) /var/log/squid/access.log | |
121 root 0:00 grep squid | |
/ # grep -rn cache_dir /etc/squid/squid.conf | |
27:cache_dir aufs /var/cache/squid 100 16 256 | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment