Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker proxy config doesn't work on Ubuntu 15.04 #133

Merged
merged 9 commits into from
Sep 19, 2015

Conversation

mrsheepuk
Copy link
Contributor

With the introduction of systemd, an extra step is required to make the proxy configuration work - analogous to the handling used for CoreOS whereby the systemd service unit is updated to pull in the environment from /etc/default/docker. I'm not experienced with Ruby so I may have made some large errors here, but this now works on my local environment against a ubuntu/vivid image.

@mrsheepuk
Copy link
Contributor Author

Well that totally failed :) I've no idea how to update the tests but I'll give it a go.

@mrsheepuk
Copy link
Contributor Author

Sorry I'm not sure how to fix this up - it looks like it's failed on a code complexity check rather than the tests as such, and I'm not sure how best to address this. If someone can point me in the right direction it would be appreciated!

@otahi
Copy link
Collaborator

otahi commented Sep 11, 2015

@mrsheepuk Thank you for your trying a pull request!! It is very welcome!!
I will check it later. I feel it could be more simple, please give me time to check with ubuntu/vivid image.

@otahi otahi self-assigned this Sep 11, 2015
@otahi
Copy link
Collaborator

otahi commented Sep 12, 2015

@mrsheepuk I cannot reproduce the problem you indicated.. It means no problem for my proxy configuration with Docker on ubuntu/vivid.

I did vagrant up with ubuntu/vivid64, next installed dcoker.io, then did vagrant reload. That seems OK. What is the difference?

Vagrant and Vagrant-proxyconf version.

[otahi@otahiair vagrant-proxyconf-issue-133]$ vagrant -v
Vagrant 1.7.4
[otahi@otahiair vagrant-proxyconf-issue-133]$ vagrant plugin list | grep -i vagrant-proxyconf
vagrant-proxyconf (1.5.1)
[otahi@otahiair vagrant-proxyconf-issue-133]$

My vagrant file

[otahi@otahiair vagrant-proxyconf-issue-133]$ cat Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/vivid64"
  config.vbguest.auto_update = false
  config.vm.provider 'virtualbox' do |v|
    v.customize ['modifyvm', :id, '--memory', '256']
  end
  config.proxy.http     = "http://user:[email protected]:8080"
  config.proxy.https    = "http://user:[email protected]:8080"
  config.proxy.no_proxy = "/var/run/docker.sock"
end

vagrant reload log

[otahi@otahiair vagrant-proxyconf-issue-133]$ vagrant reload
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'ubuntu/vivid64' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Configuring proxy for Apt...
==> default: Configuring proxy for Docker...
==> default: Configuring proxy environment variables...
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/otahi/tmp/vagrant-proxyconf-issue-133
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
[otahi@otahiair vagrant-proxyconf-issue-133]$

Check proxy related environment variables.

[otahi@otahiair vagrant-proxyconf-issue-133]$ vagrant ssh -c 'sudo strings /proc/`sudo pgrep docker|head -n1`/environ | grep -i proxy '
HTTP_PROXY=http://user:[email protected]:8080
NO_PROXY=/var/run/docker.sock
http_proxy=http://user:[email protected]:8080
no_proxy=/var/run/docker.sock
Connection to 127.0.0.1 closed.
[otahi@otahiair vagrant-proxyconf-issue-133]$

And I checked systemd exists.

[otahi@otahiair vagrant-proxyconf-issue-133]$ vagrant ssh -c 'ps -p1 | grep systemd'    1 ?        00:00:01 systemd
Connection to 127.0.0.1 closed.
[otahi@otahiair vagrant-proxyconf-issue-133]$

@mrsheepuk
Copy link
Contributor Author

@otahi Interesting - I'm using an ansible role https://github.com/angstwad/docker.ubuntu which installs the docker-engine package from the official docker repo, instead of the docker.io package from the ubuntu repos.

docker-engine is the package which the supported install process for ubuntu (https://docs.docker.com/installation/ubuntulinux/) - i.e. what you get if you run curl -sSL https://get.docker.com/ | sh

@mrsheepuk
Copy link
Contributor Author

@otahi Here's the steps to reproduce:

vagrant init ubuntu/vivid64
# add proxy config to vagrant file if needed.
vagrant up
vagrant ssh

On the ssh term:

curl -sSL https://get.docker.com/ | sh
exit

Then do the vagrant reload. I've just tried this and the proxy config does not work. Retrying this process with my pull request in place correctly configures it - although I don't know whether it's the "best" way to configure it, it does work.

It's also possible to specify the proxy in a [Service] section in a .conf file in /etc/systemd/system/docker.service.d/ which provides a side-load extra piece of config for the service - e.g. in /etc/systemd/system/docker.service.d/http-proxy.conf this works:

[Service]
Environment="HTTP_PROXY=http://10.0.0.10:8080/" "HTTPS_PROXY=http://10.0.0.10:8080/"

I don't know how such a file would get created, but it's a very clean way of configuring the proxy as it doesn't involve any assumptions about the current configuration file for the systemd service.

@otahi
Copy link
Collaborator

otahi commented Sep 14, 2015

@mrsheepuk Thank you for your quick response.

Now, I understand the installed docker package is different. I found the docker.io package reads /etc/default/docker in /lib/systemd/system/docker.service.

I will recheck with your steps.

/lib/systemd/system/docker.service in Docker's officaial package
does not include /etc/default/docker.
@otahi
Copy link
Collaborator

otahi commented Sep 16, 2015

@mrsheepuk I have added lib/vagrant-proxyconf/cap/debian/docker_proxy_conf.rb for Docker official package on Debian/Ubuntu. See otahi@b4f8689 on https://github.com/otahi/vagrant-proxyconf/tree/fix_ubuntu_docker. Can you check it?

@mrsheepuk
Copy link
Contributor Author

I'll check it in a couple of hours time - thanks!

@mrsheepuk
Copy link
Contributor Author

@otahi Thanks for this - I've just tested and it works fine on 15.04 with the official docker docker package now - however this will also apply to all versions of Debian / Ubuntu rather than just those using systemd (i.e. 15.04 onwards in Ubuntu, not sure about Debian versions but assume a similar situation there).

I've just spun up a 15.04 and 14.04 image, installed docker then done a vagrant reload - on 14.04 you now get the following error on the reload:

The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

systemctl daemon-reload

Stdout from the command:

Stderr from the command:

stdin: is not a tty
bash: line 2: systemctl: command not found

In my pull request, I was guarding against this using this line:

elsif machine.communicate.test('ps -p1 | grep systemd')

... although that's not bullet-proof, it should catch the vast majority of cases.

@otahi
Copy link
Collaborator

otahi commented Sep 17, 2015

@mrsheepuk Thank you for your indication. Yes, your are right. I was missing that. I think following matrix should be tested. I am trying to coding and testing to fill this matrix.

Guest OS \ Package docker.io package docker official package
Debian/Ubuntu systemd
Debian/Ubuntu none systemd

@otahi
Copy link
Collaborator

otahi commented Sep 18, 2015

@mrsheepuk I have implemented and tested partially.

Guest OS \ Package docker.io package docker official package
Debian/Ubuntu systemd Ubuntu 15.04 ✅
Debian/Ubuntu none systemd Ubuntu 14.04 ✅

I have not tested on none systemd systems.
If you are OK, please replace your commit to my commits with my PR mrsheepuk#1.

I will test it on none systemd systems in few days.
I will test missing part of the matrix in a few days.

I had misunderstood Ubuntu 14.04 systemd condition, so I changed some description.

@otahi
Copy link
Collaborator

otahi commented Sep 19, 2015

@mrsheepuk I have tested the matrix. And all tests are OK.

Guest OS \ Package docker.io package docker official package
Debian/Ubuntu systemd Ubuntu 15.04 ✅ Ubuntu 15.04 ✅
Debian/Ubuntu none systemd Ubuntu 14.04 ✅ Ubuntu 14.04 ✅

@mrsheepuk
Copy link
Contributor Author

@otahi Great, thanks - I'll pull in your commits and update the pull request.

mrsheepuk and others added 2 commits September 19, 2015 23:05
…eb hosts.".

This has been superceded by the pull request from @otahi.

This reverts commit 690cb77.
otahi added a commit that referenced this pull request Sep 19, 2015
Docker proxy config doesn't work on Ubuntu 15.04
@otahi otahi merged commit 7dae09e into tmatilai:master Sep 19, 2015
@otahi
Copy link
Collaborator

otahi commented Sep 19, 2015

@mrsheepuk Thank you so much! I appreciate your pull request!

@mrsheepuk
Copy link
Contributor Author

@otahi no problem, thanks for doing the actual work to integrate it successfully!

otahi added a commit to otahi/vagrant-proxyconf that referenced this pull request Sep 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants