jpetazzo / squid-in-a-can

361 stars 78 forks source link

more elaborative working example for noobs, please! #14

Closed danushk closed 7 years ago

danushk commented 9 years ago

Thanks for the brilliant concept for saving very expensive Internet bandwidth.

But i have a big issue since i am noob to docker , i could not set up your idea properly.

i started by saying :/ sudo docker run --net host jpetazzo/squid-in-a-can

2015/05/30 09:16:25 kid1| Set Current Directory to /var/spool/squid3 2015/05/30 09:16:25 kid1| Creating missing swap directories 2015/05/30 09:16:25 kid1| /var/cache/squid3 exists 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/00 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/01 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/02 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/03 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/04 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/05 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/06 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/07 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/08 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/09 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/0A 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/0B 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/0C 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/0D 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/0E 2015/05/30 09:16:25 kid1| Making directories in /var/cache/squid3/0F

and i have no room to say :// iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 3129 -w.

i wonder whether this is docker related issue, but i thought to ask starting from here. :)

So i cordially ask you to provide a more noob friendly guide here , many noobs like me will benefit from your brilliant concept.

Many Thanks

tfoote commented 9 years ago

It looks like you're missing the -d option in the command.

If you don't use the -d option it won't detach and will not return you to the command prompt. You can either open a new terminal to run the second command, background the docker instance, or rerun it with the -d option(which will detach the instance and give you the console back).

danushk commented 9 years ago

tfoote , thanks for the very quick response.

i followed your tip and here is what i got ?

dan@aspire:/etc/profile.d$ sudo docker run --net host -d jpetazzo/squid-in-a-can [sudo] password for dan: 76fb63aa738d1798797424dc13f99d7f06e4c5401a5da1095124d8afec42f60c

dan@aspire:/etc/profile.d$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 76fb63aa738d jpetazzo/squid-in-a-can:latest "/bin/sh -c /tmp/dep About a minute ago Up About a minute modest_stallman

dan@aspire:/etc/profile.d$ sudo docker exec 76fb63aa738d iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 3129 -w 2015/05/30 10:06:22 docker-exec: failed to exec: exec: "iptables": executable file not found in $PATH

i am thinking of running the iptables command inside the instance , not on the host , if its right , what does this error mean ?

tfoote commented 9 years ago

The iptables commands are run on the host not in docker. You need to redirect the communications at the host level to the docker instance.

There is a subdirectory with a Dockerfile defining container which can be run with permissions and can do the iptables routing if linked against the squid container. See the fig.yml for how to run that.

danushk commented 9 years ago

Hi tfoote , thanks for the help, i got squid in can to work and i could see that traffic is going through the squid by tailing -f the squid log files. now i am not getting what i was looking for. here what it is

desktop 1_007

There u can see the squid is running

desktop 1_008

Here you can see that lemp stack is running

desktop 1_009

Here is the problem - i fired up a new docker instance and tried to repeat the same lemp stack installation process while no internet. i was expecting docker to fetch from squid persistent cache rather than from internet. But its not working. am i missing something here ?

tfoote commented 9 years ago

This instance of squid is configured as a proxy accelerator, and for correctness always checks upstream for changes before giving you the cached results. It is not setup to work entirely offline. You will need to customize the squid configuration to support that use case.

danushk commented 9 years ago

i believe much easier method than your idea is to make /var/cache/apt folder a persistent volume with -v. docker irc channel also proposed the same plan. i will test it and let you know.

ZoomyCat commented 7 years ago

Any update on getting this to be used as a docker cache. I'm running a docker-machine boot2docker instance with dind building. Caching docker images persistently would be pretty awesome.

jpetazzo commented 7 years ago

It will probably be hard to use this image as a registry cache.

However, the registry v2 supports caching; see this blog post for more details.

Thank you!