Docker Squid Cache and MacOS

Datetime:2017-04-20 05:35:53         Topic: Docker  MacOS          Share        Original >>
Here to See The Original Article!!!

I pull a lot of things down from the internet. I seem to pull the same thing weather it be a gem or iso over and over. I finally decided to create a local Squid proxy, to cache my downloads so I don’t have to keep going out to the internet to pull things down.

First thing first. Install Docker. There are a ton of how-tos, I’d google for em.

Awesome, lets start the next part. Pull down the defacto squid container:

$ docker pull sameersbn/squid:3.3.8-23

You can use :latest if you want, but this was the version I picked for no specific reason.

Next, you’ll need to find a place for your cache. By default Docker file-shares the /Users directory on MacOS so this is what I did:

$ mkdir -p ~/squid/cache/

Start up the container!

$  docker run --name squid -d --restart=always \
>   --publish 3128:3128 \
>   --volume /Users/jjasghar/squid/cache:/var/spool/squid3 \
>   sameersbn/squid:3.3.8-23

Check that the container is running:

$ docker ps
CONTAINER ID        IMAGE                      COMMAND                 CREATED             STATUS              PORTS                    NAMES
6d245aedb504        sameersbn/squid:3.3.8-23   "/sbin/"   3 minutes ago       Up 3 minutes>3128/tcp   squid

Next, figure out the IP, for me it was utun4 , then export out some settings to bash:

$ ifconfig
[-- snip --]
utun4: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1500
	inet --> netmask 0xffff0000
	inet6 fe80::f65c:89ff:feca:6527%utun4 prefixlen 64 scopeid 0x12
	inet6 2001:470:bb7b:ffff::14 prefixlen 64
	nd6 options=201<PERFORMNUD,DAD>
$ export ftp_proxy=
$ export http_proxy=
$ export https_proxy=

With this, you can now run, in a different terminal:

$ docker exec -it squid tail -f /var/log/squid3/access.log

And curl google:

$ curl

You should see something like the following in the access.log window:

1492635161.351    529 TCP_MISS/200 15223 CONNECT - HIER_DIRECT/ -

Congrats, you have a working proxy now. Lets do some configuration, stop your container:

$ docker stop squid

Now go to your ~/squid directory, and pull down the main squid.conf to it, and open it up in your text editor:

$ cd squid
~/squid $ wget
~/squid $ emacs squid.conf

Make any changes you think you might need, I’m still learning them myself. After your done, start it back up!

$  docker run --name squid -d --restart=always \
>   --publish 3128:3128 \
>   --volume /Users/jjasghar/squid/cache:/var/spool/squid3 \
>   --volume /Users/jjasghar/squid.conf:/etc/squid3/squid.conf \
>   sameersbn/squid:3.3.8-23