jpetazzo / squid-in-a-can

361 stars 78 forks source link

Bower-Npm Behind Corporate Proxy #4

Closed sesteva closed 9 years ago

sesteva commented 9 years ago

I could not get more information on google group, stackoverflow. You are my last resource. https://groups.google.com/forum/#!topic/docker-user/vc3PF0aRjYQ

Im am behind a corporate proxy. I have a squid running on 3128. Locally - in the host - if I run npm or bower everything goes trhough the proxy and works as expected.

I want to run bower update or npm update inside the running container. Basically the traffic should be run through docker which should in return run via the squid proxy.

I looked at https://docs.docker.com/installation/ubuntulinux/ and reading on forums, the instruction is to update /etc/default/docker to export the proxy setup.

 export http_proxy="http://127.0.0.1:3128/"
 export https_proxy="http://127.0.0.1:3128/"
 export HTTP_PROXY="http://127.0.0.1:3128/"
 export HTTPS_PROXY="http://127.0.0.1:3128/"

Then we restart/start docker

 sudo service docker start

Inside a container, if I run 'apt-get', npm install, bower install I cant get through. I think this docker container should fix my problem but I have not been succesful so far.

Thanks - Santiago

tfoote commented 9 years ago

All network communications does not run through docker.

The proxy settings in the config will only effect the files that docker downloads directly(usually pulling images from hub.docker.io) but nothing more. The iptables rules are what catch all data from containers and redirect it to the proxy. Are you running the iptables commands? Also the iptables rules only intercept http requests, https communications are designed to prevent man in the middle attacks.

Your best solution for https support will probably be to setup your containers and export http(s)_proxy setting inside your container and point it to the address of your squid container's proxy port. (possibly using linking or the host network adapter if the squid proxy is running with --net option). You can also switch to use http instead of https for things like npm: https://stackoverflow.com/questions/8874363/npm-install-without-ssl

sesteva commented 9 years ago

Fixed. I have a squid instance running on the host on port 3128

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 3128

Inside the container I did

export http_proxy="http://172.17.42.1:3128/"
export https_proxy="http://172.17.42.1:3128/"
git config --global url."https://".insteadOf git://

I also had to update my squid config to allow the requests from docker ip range