tmatilai / vagrant-proxyconf

Vagrant plugin that configures the virtual machine to use proxies
MIT License
531 stars 74 forks source link

proxy settings not propagated to docker? #97

Closed dkoper closed 9 years ago

dkoper commented 9 years ago

Not sure if this is a feature request or a bug. I'm behind a corporate proxy, so need http proxy on all Internet connections. My Vagrantfile includes:

Vagrant.configure(2) do |config|
  config.vm.box = 'ubuntu/trusty64'

  config.vm.provider(:virtualbox) do |v|
...
  end

  if Vagrant.has_plugin?("vagrant-proxyconf")
    if ENV["http_proxy"]
      config.proxy.http        = ENV["http_proxy"]
    end
    if ENV["https_proxy"]
      config.proxy.https        = ENV["https_proxy"]
    end
  end

  config.vm.provision('docker')
end

and http_proxy envs are exported on my ubuntu 14 machine. Box is downloaded successfully, docker is successfully provisioned, but when I vagrant ssh and docker pull <img>, I get a connection timed out. When I manually add http_proxy vars to /etc/default/docker and service docker restart, docker pull works fine. Isn't vagrant-proxyconf supposed to set it for me automatically? If not, how can I configure it to do so? I'm using vagrant-proxyconf 1.4.0 and latest vagrant.

otahi commented 9 years ago

Hi @dkoper,

Vagrant-proxyconf checks if docker is installed or not. So if no docker installed, no configuration change. If docker is installed, vagrant-proxyconf configures docker file. So, I think you can get a configured VM when restart your VM.

dkoper commented 9 years ago

Yes! After a vagrant reload http proxy appeared in /etc/default/docker and docker pull works. Thanks!

Any particular reason you don't add https_proxy entries as well? Are there no secure docker repo's? https://github.com/tmatilai/vagrant-proxyconf/blob/master/lib/vagrant-proxyconf/action/configure_docker_proxy.rb#L86

Also, is there no way for the plugin to query my Vagrantfile, notice the config.vm.provision('docker') and configure the proxy for it without the restart?

otahi commented 9 years ago

Sounds nice that works!

Any particular reason you don't add https_proxy entries as well? Are there no secure docker repo's?

Docker seems to use http_proxy for both http and https. See registry.go:53

Also, is there no way for the plugin to query my Vagrantfile, notice the config.vm.provision('docker') and configure the proxy for it without the restart?

It will be a feature request because there is a no special implementation for config.vm.provision('docker').

dkoper commented 9 years ago

Cheers. I'll create a new issue.

kartikgupta0909 commented 9 years ago

This is my Vagrant file Vagrant.configure("2") do |config| config.proxy.http = "http://proxy.iiit.ac.in:8080" config.proxy.https = "https://proxy.iiit.ac.in:8080" config.proxy.no_proxy = "localhost,127.0.0.1" config.vm.box = "hashicorp/precise64" config.vm.network "forwarded_port", guest: 8888, host: 8888 config.vm.network "forwarded_port", guest: 8000, host: 8000 config.vm.network "forwarded_port", guest: 15672, host: 15672 config.vm.network "forwarded_port", guest: 3305, host: 3305 config.vm.provision "docker" do |d| d.run "johnlzeller/rabbitmq-app", args: "-d -p 5672:5672 -p 15672:15672 -p 4369:4369 --name='rabbitmq'" d.run "johnlzeller/mysql-app", args: "-d -p 3306:3306 --name='mysql'" d.run "johnlzeller/buildbot-app", args: "-d -p 8000:8000 --link=mysql:sql --name='buildbot'" d.run "johnlzeller/buildapi-app", args: "-d -p 8888:8888 --link=rabbitmq:mq --link=mysql:sql --name='buildapi'" end end

Now when i run this , it gives me an error Unable to find image 'johnlzeller/rabbitmq-app:latest' locally time="2015-02-16T17:34:53Z" level="fatal" msg="Error: 404 page not found" I think this happens because it tries to access the containers before setting the proxy for docker, can you help me how to fix this?

otahi commented 9 years ago

@kartikgupta0909, Can you give more information? I think it is not a problem of vagrant-proxyconf because Error: 404 shows us the target server or your proxy server returns an error. If vagrant-proxyconf does not work, I think it will cause a DNS error or a TCP socket error or something...

So Please give;

Thank you,

kartikgupta0909 commented 9 years ago

@otahi Vagrant Version: 1.7.2 Docker Version: 1.5.0 Outputs sudo strings /proc/pgrep docker/environ | grep http_proxy : http_proxy=http://proxy.iiit.ac.in:8080/

env | grep http: http_proxy=http://proxy.iiit.ac.in:8080/ https_proxy=https://proxy.iiit.ac.in:8080/ And yes curl and wget commands work fine And this is the link to the log: https://gist.github.com/kartikgupta0909/a3375ef3812dbadd5c6d

otahi commented 9 years ago

@kartikgupta0909 Docker 1.5 reminds me #109. Can you try no_proxy with .sock?

kartikgupta0909 commented 9 years ago

@otahi I tried this , still not working. One thing i want you to note is that , whenever i run vagrant up , i cant actually see the log where proxy is being configured for docker , but when i remove the part the application part from my vagrant file , i can actually see a log which says configuring proxy for docker.

otahi commented 9 years ago

@kartikgupta0909 I am sorry that I could not see the log file at that time.

I had to asked you this point at the first. It is very important point.

One thing i want you to note is that , whenever i run vagrant up

I am checking the log and there is not log for Docker proxy as you said. Vagrant-proxyconf for Docker expect Docker is installed before configuration. If there is no Docker on the VM, vagrant-proxyconf does not configure proxy for Docker. When you reload vagrant with vagrant reload or use Docker pre-installed image, vagrant-proxyconf will configure proxy.

By the way, you mentioned;

sudo strings /proc/pgrep docker/environ | grep http_proxy : http_proxy=http://proxy.iiit.ac.in:8080/

If Docker have http_proxy, it can access with the proxy server. Can you check the following commands because I want to check the Docker process really have http_proxy environment?

pgrep -l docker
sudo cat /proc/<<process ids above>>/environ

Thank you,

jensklose commented 9 years ago

please try again the no_proxy change:

config.proxy.no_proxy = "/var/run/docker.sock,localhost,127.0.0.1"

I've the same issue and this was the solution.