tmatilai / vagrant-proxyconf

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

Docker Support #74

Closed mfehlhaber closed 9 years ago

mfehlhaber commented 10 years ago

vagrant (1.6.3) with vagrant-proxyconf (1.3.2) on Win7/64:

vagrant up --provider=docker

failed. From within boot2docker:

docker pull phusion/baseimage

wasn't able to access repository while

curl https://index.docker.io/v1/repositories/phusion/baseimage/images

worked fine. I had to manually add HTTP_PROXY and HTTPS_PROXY to /var/lib/boot2docker/profile to get things working.

otahi commented 10 years ago

@mfehlhaber Thank you for trying docker support.

Unfortunately this feature is not released yet. https://github.com/tmatilai/vagrant-proxyconf/blob/master/CHANGELOG.md

You can use prerelease version with the following instruction

Please try it until release and be sure there is an issue which I am fixing #73.

tmatilai commented 10 years ago

@mfehlhaber as @otahi said, the docker support is not yet released (but will be soonish). Have you tried the bleeding edge version?

mfehlhaber commented 10 years ago

No, I have not. I am using CoreOS as docker-host currently. The setting of a proxy is well described on their site. Since the docker-host stays up pretty much all the time, it does not bother me enough to take the extra steps.

tmatilai commented 10 years ago

@mfehlhaber it would be great if you anyway could test that the docker support works as expected. And please at least reopen the issue if you hit into any problems after v1.4 is released.

mfehlhaber commented 10 years ago

@tmatilai I will surely check v1.4 out and let you know if it works for me. It's only on a windows machine at work I have to use a proxy and there ruby/gem is hidden behind vagrant. Thus my reluctance to try the pre-release version...

what the hell... after some going back an forth between cygwin/bash and cmd.exe:

$ vagrant plugin list
vagrant-login (1.0.1, system)
vagrant-proxyconf (1.4.0.dev)
  - Version Constraint: 1.4.0.dev
vagrant-share (1.1.0, system)

$ vagrant up --provider=docker
...
An error occurred while executing the action on the 'play'
machine. Please handle this error then try again:

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

service docker restart || /etc/init.d/docker restart

Stdout from the command:

Stderr from the command:
bash: line 2: service: command not found
bash: line 2: /etc/init.d/docker: No such file or directory

On docker-host (which for me is CoreOS) not even the environment variables were set. I have to revert back to the released version, since vagrant-proxyconf insists on trying to restart docker in a way that does not work on CoreOS.

$ vagrant plugin uninstall vagrant-proxyconf
$ vagrant plugin install vagrant-proxyconf
Installing the 'vagrant-proxyconf' plugin. This can take a few minutes...
Installed the plugin 'vagrant-proxyconf (1.3.2)'!

and set my proxy up manually

$ cd docker-host
$ vagrant ssh

core@localhost ~ $ sudo cp /usr/lib/systemd/system/docker.service /etc/systemd/system/
core@localhost ~ $ sudo vim /etc/systemd/system/docker.service

First thing in [Service]

Environment="HTTP_PROXY=http://proxy.example.com:8080"

and now to restart on CoreOS

core@localhost ~ $ sudo systemctl daemon-reload
core@localhost ~ $ sudo systemctl restart docker
core@localhost ~ $ exit
otahi commented 10 years ago

@mfehlhaber Thank you for trying and giving a description!

I am trying to reproduce this by myself. And I think I have almost reproduced. I think CoreOS is very different from other Linux distributions. So I need to consult CoreOS at first...

mfehlhaber commented 10 years ago

@otahi Quite correct. CoreOS is a stange beast in comparison. I chose it as docker-host because docker is native for this system.

To start it, I am using this simple Vagrantfile (the host configuration is totally optional, but I like the name host better than default):

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "yungsang/coreos"
  config.vm.define "host" do |host|
  end
end

From the main Vagrantfile, I link to this docker-host like this (and if you kept the name default for your docker-host, you wouldn't have to specify the name host here):

config.vm.define "play" do |app|
  app.vm.provider "docker" do |d|
    ...
    d.force_host_vm = true
    d.vagrant_machine = "host"
    d.vagrant_vagrantfile = "./docker-host/Vagrantfile"
  end
end
otahi commented 10 years ago

@mfehlhaber I have googled and found Using Cloud-Config.

For CoreOS, is following way natural? If so, vagrant-proxyconf is not necessary for CoreOS.

I did like this.

git clone https://github.com/coreos/coreos-vagrant/
cd coreos-vagrant
vi user-data

user-data :

#cloud-config

coreos:
  units:
    - name: docker.service
      command: start
      enable: true
      content: |
            mentation=http://docs.docker.io

            [Service]
            Environment="http_proxy=http://myproxy:3128/"
            ExecStartPre=/bin/mount --make-rprivate /
            LimitNOFILE=1048576
            LimitNPROC=1048576
            # Run docker but don't have docker automatically restart
            # containers. This is a job for systemd and unit files.
            ExecStart=/usr/bin/docker -d -s=btrfs -r=false -H fd://

            [Install]
            WantedBy=multi-user.target

Then, vagrant up and vagrant reload --provision (it maybe requires reload.)

$ vagrant ssh
Last login: Tue Jul  8 21:41:16 2014 from 10.0.2.2
CoreOS (alpha)
core@core-01 ~ $ sudo cat /proc/`pgrep docker`/environ
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binLISTEN_PID=438LISTEN_FDS=1http_proxy=http://myproxy:3128/core@core-01 ~ $
mfehlhaber commented 10 years ago

@otahi while a proxy can be set this way for CoreOS, I'd still very much prefer vagrant-proxyconf over this. Using user-data is basically like putting proxy environment settings in a Dockerfile. You wouldn't want that either. Setting proxy in a central, but machine specific Vargantfile that does not end-up on GitHub is way better.

otahi commented 10 years ago

@mfehlhaber I understand what you mean. I will try to fix this on #75 because RHEL7 and CoreOS both have systemctl.

otahi commented 10 years ago

@mfehlhaber I did not fix this issue on #75. I will create another pull request after #75 merged.

otahi commented 10 years ago

I am trying implementation. On my environment, it seems that works OK with like following Vagrantfile.

Vagrant.configure("2") do |config|
  config.vm.box = 'coreos-alpha'
  config.proxy.http     = 'http://192.168.11.4:3128/'
  config.proxy.no_proxy = 'localhost,127.0.0.1,.example.com'
end

@mfehlhaber, if you can, try my branch https://github.com/otahi/vagrant-proxyconf coreos_support branch git pull && git checkout add_docker_coreos_support

For CoreOS is c31a4ba added on #75.

mfehlhaber commented 10 years ago

@otahi basically works for me, good job!

An issue seems to be remaining though: Linking between docker containers now fails. I might be able to fix this by setting an appropriate _config.proxy.noproxy. This problem did not exist, when I formerly set the proxy manually as described in https://github.com/tmatilai/vagrant-proxyconf/issues/74#issuecomment-48285340.

mfehlhaber commented 10 years ago

Something else I have encountered while creating a docker image/container from a Dockerfile:

==> play: Docker host is required. One will be created if necessary...
    play: Docker host VM is already ready.
==> play: Syncing folders to the host VM...
    play: Configuring proxy for Docker...
    play: Configuring proxy environment variables...
    play: Rsyncing folder: /cygdrive/c/Users/<user>/doplay/ => /var/lib/docker/docker_1405334221_65770
    play: Rsyncing folder: /cygdrive/c/Users/<user>/doplay/ => /mnt/docker_build_94b501df55ef14a2eaaeb25d58b7db04
==> play: Building the container from a Dockerfile...
==> play: An error occurred. The error will be shown after all tasks complete.

Command: "docker" "build" "-t" "<user>/doplay" "/mnt/docker_build_94b501df55ef14a2eaaeb25d58b7db04"

Stderr: Sending build context to Docker daemon 251.9 kB
Sending build context to Docker daemon
2014/07/14 10:45:14 The command [/bin/sh -c apt-get update && apt-get -y install redis-tools] returned a non-zero code: 100

Stdout: Step 0 : FROM phusion/baseimage:latest
 ---> dabfc8a44cb5
Step 1 : ENV HOME /root
 ---> Using cache
 ---> 2546fe8558b9
Step 2 : CMD ["/sbin/my_init", "--enable-insecure-key"]
 ---> Using cache
 ---> b18de25f51cf
Step 3 : RUN apt-get update && apt-get -y install redis-tools
 ---> Running in 4bc76ca155d0
Err http://archive.ubuntu.com trusty InRelease

Err http://archive.ubuntu.com trusty-updates InRelease

Err http://archive.ubuntu.com trusty-security InRelease

Err http://archive.ubuntu.com trusty Release.gpg
  Unable to connect to archive.ubuntu.com:http: [IP: 91.189.91.13 80]
...

If I don't do the apt-get in the Dockerfile, but immediately after the container is up via ssh, everything works just fine.

otahi commented 10 years ago

@mfehlhaber Thank you for trying. Do you mean my modification has no problem for you?

Vagrant-proxyconf settings takes effect to docker processes on 'Host', but not to containers. apt-get does not work because of no http_proxy or no_proxy environment variables.

I think you can apt-get with a config file on a container(like '/etc/apt/apt.conf.d/01proxy').

tmatilai commented 10 years ago

If I understand correctly, this should be fixed now by #75 and #80. /cc @otahi

otahi commented 10 years ago

@tmatilai Yes. I think you are right. This is already fixed.

dduportal commented 10 years ago

Ping @tmatilai @otahi : are we up yet to a 1.4.0 release ?

otahi commented 10 years ago

@dduportal I think it will be released in the not too distant future. @tmatilai Is it correct?

dduportal commented 10 years ago

If i can help for anything, don't hesitate !

tmatilai commented 10 years ago

Coming soon... =) Any confirmations that the master branch works would be helpful.

otahi commented 10 years ago

@tmatilai Just tested on my PC behind proxy and it works well for me with installation from master branch.

No problem for me :smile: (it means not only docker, but also curl, apt)

(I added vagrant version: 1.6.3 at Sep 18 11:40 UTC)

$ vagrant --version
Vagrant 1.6.3
$ vagrant plugin list  | grep dev
vagrant-proxyconf (1.4.0.dev)
  - Version Constraint: 1.4.0.dev
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> 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: Adapter 2: hostonly
(snip)
==> default: Configuring proxy for Apt...
==> default: Configuring proxy for Chef provisioners...
==> default: Configuring proxy for Docker...
==> default: Configuring proxy environment variables...
==> default: Configuring proxy for npm...
(snip)

$ sudo docker search -s 400 centos
NAME      DESCRIPTION                     STARS     OFFICIAL   AUTOMATED
centos    The official build of CentOS.   430       [OK]
$
otahi commented 10 years ago

I have tested vagrant-proxyconf with the latest vagrant.

It works OK.

$ vagrant --version
Vagrant 1.6.5
$ vagrant plugin list  | grep dev
vagrant-proxyconf (1.4.0.dev)
  - Version Constraint: 1.4.0.dev
$
tmatilai commented 9 years ago

v1.4.0 released. Thanks to everyone, especially to @otahi!

otahi commented 9 years ago

@tmatilai Thank you!!! I appreciate your keeping support!! @dduportal , @mfehlhaber Thank your for watching and help. Again, thank you everyone!