tmatilai / vagrant-proxyconf

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

Proxy doesn't work for Docker with systemd #172

Closed ghost closed 5 years ago

ghost commented 6 years ago

I expect that proxy is set for docker, but is not.

Versions

> vagrant --version
Vagrant 2.1.1
> vagrant plugin list
vagrant-proxyconf (1.5.2)
vagrant-vbguest (0.15.2)

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vbguest.auto_update = false

  proxy = ENV['WITH_PROXY']
  config.proxy.http = proxy
  config.proxy.https = proxy
  print "PROXY HTTP: ", config.proxy.http, "\n"
  print "PROXY HTTPS: ", config.proxy.https, "\n"

  config.vm.provision "shell", inline: <<-SHELL
      apt-get update
      apt-get -y remove \
        docker \
        docker-engine \
        docker.io
      apt-get -y install \
        apt-transport-https \
        ca-certificates \
        curl \
        software-properties-common
      curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
      add-apt-repository \
         "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
         $(lsb_release -cs) \
         stable"
      apt-get update
      apt-get install -y docker-ce
      docker run hello-world
  SHELL
  config.vm.provision "shell", run: "always", inline: <<-SHELL
      # FROM: https://docs.docker.com/config/daemon/systemd/#httphttps-proxy
      systemctl show --property=Environment docker
  SHELL
end

Here's the test with output:

> vagrant up
PROXY HTTP: 
PROXY HTTPS: 
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/bionic64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/bionic64' is up to date...
==> default: A newer version of the box 'ubuntu/bionic64' for provider 'virtualbox' is
==> default: available! You currently have version '20180531.0.0'. The latest is version
==> default: '20180809.0.0'. Run `vagrant box update` to update.
==> default: Setting the name of the VM: test-vagrant-proxy-and-docker_default_1533897778098_36172
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2200 (host) (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:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection reset. Retrying...
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /home/xliiv/workspace/test-vagrant-proxy-and-docker
==> default: Running provisioner: shell...
    default: Running: inline script
    default: Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
    default: Get:2 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
    default: Get:3 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
    default: Get:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
    default: Get:5 http://archive.ubuntu.com/ubuntu bionic/multiverse Sources [181 kB]
    default: Get:6 http://archive.ubuntu.com/ubuntu bionic/restricted Sources [5324 B]
    default: Get:7 http://archive.ubuntu.com/ubuntu bionic/main Sources [829 kB]
    default: Get:8 http://archive.ubuntu.com/ubuntu bionic/universe Sources [9051 kB]
    default: Get:9 http://security.ubuntu.com/ubuntu bionic-security/multiverse Sources [1336 B]
    default: Get:10 http://security.ubuntu.com/ubuntu bionic-security/main Sources [39.3 kB]
    default: Get:11 http://security.ubuntu.com/ubuntu bionic-security/universe Sources [13.1 kB]
    default: Get:12 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [133 kB]
    default: Get:13 http://security.ubuntu.com/ubuntu bionic-security/main Translation-en [52.2 kB]
    default: Get:14 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [48.6 kB]
    default: Get:15 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [8570 kB]
    default: Get:16 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [27.4 kB]
    default: Get:17 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [1440 B]
    default: Get:18 http://security.ubuntu.com/ubuntu bionic-security/multiverse Translation-en [996 B]
    default: Get:19 http://archive.ubuntu.com/ubuntu bionic/universe Translation-en [4941 kB]
    default: Get:20 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [151 kB]
    default: Get:21 http://archive.ubuntu.com/ubuntu bionic/multiverse Translation-en [108 kB]
    default: Get:22 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse Sources [2676 B]
    default: Get:23 http://archive.ubuntu.com/ubuntu bionic-updates/main Sources [152 kB]
    default: Get:24 http://archive.ubuntu.com/ubuntu bionic-updates/universe Sources [53.2 kB]
    default: Get:25 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [277 kB]
    default: Get:26 http://archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [105 kB]
    default: Get:27 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [158 kB]
    default: Get:28 http://archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [71.4 kB]
    default: Get:29 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [3772 B]
    default: Get:30 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse Translation-en [2376 B]
    default: Get:31 http://archive.ubuntu.com/ubuntu bionic-backports/universe Sources [1184 B]
    default: Get:32 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [2704 B]
    default: Get:33 http://archive.ubuntu.com/ubuntu bionic-backports/universe Translation-en [1136 B]
    default: Fetched 25.2 MB in 7s (3839 kB/s)
    default: Reading package lists...
    default: Reading package lists...
    default: Building dependency tree...
    default: 
    default: Reading state information...
    default: Package 'docker-engine' is not installed, so not removed
    default: Package 'docker' is not installed, so not removed
    default: Package 'docker.io' is not installed, so not removed
    default: 0 upgraded, 0 newly installed, 0 to remove and 115 not upgraded.
    default: Reading package lists...
    default: Building dependency tree...
    default: Reading state information...
    default: ca-certificates is already the newest version (20180409).
    default: The following additional packages will be installed:
    default:   libcurl4 python3-software-properties
    default: The following NEW packages will be installed:
    default:   apt-transport-https
    default: The following packages will be upgraded:
    default:   curl libcurl4 python3-software-properties software-properties-common
    default: 4 upgraded, 1 newly installed, 0 to remove and 111 not upgraded.
    default: Need to get 407 kB of archives.
    default: After this operation, 152 kB of additional disk space will be used.
    default: Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 apt-transport-https all 1.6.3 [1692 B]
    default: Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 curl amd64 7.58.0-2ubuntu3.2 [159 kB]
    default: Get:3 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libcurl4 amd64 7.58.0-2ubuntu3.2 [214 kB]
    default: Get:4 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 software-properties-common all 0.96.24.32.4 [9916 B]
    default: Get:5 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-software-properties all 0.96.24.32.4 [22.3 kB]
    default: dpkg-preconfigure: unable to re-open stdin: No such file or directory
    default: Fetched 407 kB in 0s (834 kB/s)
    default: Selecting previously unselected package apt-transport-https.
    default: (Reading database ... 
(Reading database ... 55%abase ... 5%
    default: (Reading database ... 60%
    default: (Reading database ... 65%
    default: (Reading database ... 70%
    default: (Reading database ... 75%
    default: (Reading database ... 80%
    default: (Reading database ... 85%
    default: (Reading database ... 90%
    default: (Reading database ... 95%
(Reading database ... 59609 files and directories currently installed.)
    default: Preparing to unpack .../apt-transport-https_1.6.3_all.deb ...
    default: Unpacking apt-transport-https (1.6.3) ...
    default: Preparing to unpack .../curl_7.58.0-2ubuntu3.2_amd64.deb ...
    default: Unpacking curl (7.58.0-2ubuntu3.2) over (7.58.0-2ubuntu3.1) ...
    default: Preparing to unpack .../libcurl4_7.58.0-2ubuntu3.2_amd64.deb ...
    default: Unpacking libcurl4:amd64 (7.58.0-2ubuntu3.2) over (7.58.0-2ubuntu3.1) ...
    default: Preparing to unpack .../software-properties-common_0.96.24.32.4_all.deb ...
    default: Unpacking software-properties-common (0.96.24.32.4) over (0.96.24.32.3) ...
    default: Preparing to unpack .../python3-software-properties_0.96.24.32.4_all.deb ...
    default: Unpacking python3-software-properties (0.96.24.32.4) over (0.96.24.32.3) ...
    default: Setting up apt-transport-https (1.6.3) ...
    default: Setting up libcurl4:amd64 (7.58.0-2ubuntu3.2) ...
    default: Processing triggers for libc-bin (2.27-3ubuntu1) ...
    default: Processing triggers for man-db (2.8.3-2) ...
    default: Setting up python3-software-properties (0.96.24.32.4) ...
    default: Processing triggers for dbus (1.12.2-1ubuntu1) ...
    default: Setting up software-properties-common (0.96.24.32.4) ...
    default: Setting up curl (7.58.0-2ubuntu3.2) ...
    default: Warning: apt-key output should not be parsed (stdout is not a terminal)
    default: OK
    default: Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
    default: Hit:2 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
    default: Get:3 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB]
    default: Hit:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
    default: Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease
    default: Get:6 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages [1433 B]
    default: Fetched 65.9 kB in 1s (118 kB/s)
    default: Reading package lists...
    default: Hit:1 https://download.docker.com/linux/ubuntu bionic InRelease
    default: Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease
    default: Hit:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
    default: Hit:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
    default: Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease
    default: Reading package lists...
    default: Reading package lists...
    default: Building dependency tree...
    default: Reading state information...
    default: The following additional packages will be installed:
    default:   aufs-tools cgroupfs-mount libltdl7 pigz
    default: The following NEW packages will be installed:
    default:   aufs-tools cgroupfs-mount docker-ce libltdl7 pigz
    default: 0 upgraded, 5 newly installed, 0 to remove and 111 not upgraded.
    default: Need to get 40.3 MB of archives.
    default: After this operation, 198 MB of additional disk space will be used.
    default: Get:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 pigz amd64 2.4-1 [57.4 kB]
    default: Get:2 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce amd64 18.06.0~ce~3-0~ubuntu [40.1 MB]
    default: Get:3 http://archive.ubuntu.com/ubuntu bionic/universe amd64 aufs-tools amd64 1:4.9+20170918-1ubuntu1 [104 kB]
    default: Get:4 http://archive.ubuntu.com/ubuntu bionic/universe amd64 cgroupfs-mount all 1.4 [6320 B]
    default: Get:5 http://archive.ubuntu.com/ubuntu bionic/main amd64 libltdl7 amd64 2.4.6-2 [38.8 kB]
    default: dpkg-preconfigure: unable to re-open stdin: No such file or directory
    default: Fetched 40.3 MB in 4s (9203 kB/s)
    default: Selecting previously unselected package pigz.
    default: (Reading database ... 
(Reading database ... 55%abase ... 5%
    default: (Reading database ... 60%
    default: (Reading database ... 65%
    default: (Reading database ... 70%
    default: (Reading database ... 75%
    default: (Reading database ... 80%
    default: (Reading database ... 85%
    default: (Reading database ... 90%
    default: (Reading database ... 95%
(Reading database ... 59613 files and directories currently installed.)
    default: Preparing to unpack .../archives/pigz_2.4-1_amd64.deb ...
    default: Unpacking pigz (2.4-1) ...
    default: Selecting previously unselected package aufs-tools.
    default: Preparing to unpack .../aufs-tools_1%3a4.9+20170918-1ubuntu1_amd64.deb ...
    default: Unpacking aufs-tools (1:4.9+20170918-1ubuntu1) ...
    default: Selecting previously unselected package cgroupfs-mount.
    default: Preparing to unpack .../cgroupfs-mount_1.4_all.deb ...
    default: Unpacking cgroupfs-mount (1.4) ...
    default: Selecting previously unselected package libltdl7:amd64.
    default: Preparing to unpack .../libltdl7_2.4.6-2_amd64.deb ...
    default: Unpacking libltdl7:amd64 (2.4.6-2) ...
    default: Selecting previously unselected package docker-ce.
    default: Preparing to unpack .../docker-ce_18.06.0~ce~3-0~ubuntu_amd64.deb ...
    default: Unpacking docker-ce (18.06.0~ce~3-0~ubuntu) ...
    default: Setting up aufs-tools (1:4.9+20170918-1ubuntu1) ...
    default: Processing triggers for ureadahead (0.100.0-20) ...
    default: Setting up cgroupfs-mount (1.4) ...
    default: Processing triggers for libc-bin (2.27-3ubuntu1) ...
    default: Processing triggers for systemd (237-3ubuntu10) ...
    default: Setting up libltdl7:amd64 (2.4.6-2) ...
    default: Processing triggers for man-db (2.8.3-2) ...
    default: Setting up pigz (2.4-1) ...
    default: Setting up docker-ce (18.06.0~ce~3-0~ubuntu) ...
    default: Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
    default: Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
    default: Processing triggers for ureadahead (0.100.0-20) ...
    default: Processing triggers for libc-bin (2.27-3ubuntu1) ...
    default: Processing triggers for systemd (237-3ubuntu10) ...
    default: Unable to find image 'hello-world:latest' locally
    default: latest: Pulling from library/hello-world
    default: 9db2ca6ccae0: Pulling fs layer
    default: 9db2ca6ccae0: Verifying Checksum
    default: 9db2ca6ccae0: Download complete
    default: 9db2ca6ccae0: Pull complete
    default: Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
    default: Status: Downloaded newer image for hello-world:latest
    default: 
    default: Hello from Docker!
    default: This message shows that your installation appears to be working correctly.
    default: 
    default: To generate this message, Docker took the following steps:
    default:  1. The Docker client contacted the Docker daemon.
    default:  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    default:     (amd64)
    default:  3. The Docker daemon created a new container from that image which runs the
    default:     executable that produces the output you are currently reading.
    default:  4. The Docker daemon streamed that output to the Docker client, which sent it
    default:     to your terminal.
    default: 
    default: To try something more ambitious, you can run an Ubuntu container with:
    default:  $ docker run -it ubuntu bash
    default: 
    default: Share images, automate workflows, and more with a free Docker ID:
    default:  https://hub.docker.com/
    default: 
    default: For more examples and ideas, visit:
    default:  https://docs.docker.com/engine/userguide/
==> default: Running provisioner: shell...
    default: Running: inline script
    default: Environment=

default: Environment= equal to "" so far so good, but when doing

> env WITH_PROXY="http://127.0.0.1:3128" vagrant reload
PROXY HTTP: http://127.0.0.1:3128
PROXY HTTPS: http://127.0.0.1:3128
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'ubuntu/bionic64' is up to date...
==> default: A newer version of the box 'ubuntu/bionic64' for provider 'virtualbox' is
==> default: available! You currently have version '20180531.0.0'. The latest is version
==> default: '20180809.0.0'. Run `vagrant box update` to update.
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2200 (host) (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:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection reset. 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 => /home/xliiv/workspace/test-vagrant-proxy-and-docker
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
==> default: Running provisioner: shell...
    default: Running: inline script
    default: Environment=
==> default: Configuring proxy for Docker...

is still

default: Environment=

and i expect

default: Environment=HTTP_PROXY=http://127.0.0.1:3128 HTTPS_PROXY=http://127.0.0.1:3128

see: https://docs.docker.com/config/daemon/systemd/#httphttps-proxy

brunowego commented 5 years ago

I have same issue. By now I am setting manually:

sudo mkdir -p /etc/systemd/system/docker.service.d
cat <<EOF | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=$http_proxy"
Environment="HTTPS_PROXY=$https_proxy"
Environment="NO_PROXY=localhost,127.0.0.1"
EOF
sudo systemctl daemon-reload
sudo systemctl show --property Environment docker
sudo systemctl restart docker

This is used by docker pull.

brunowego commented 5 years ago

Another issue is with the proxy inside the container used by yum, apt, zypper, etc...

mkdir -p ~/.docker
echo '{}' \
  | jq ".proxies.default.httpProxy |= \"$http_proxy\"" \
  | jq ".proxies.default.httpsProxy |= \"$https_proxy\"" \
  | jq ".proxies.default.noProxy |= \"$no_proxy\"" \
  > ~/.docker/config.json
codylane commented 5 years ago

Hi Guys - I don't believe this plugin currently supports systemd configured docker due to the many different ways that docker could be installed inside a vagrant vm. I think I saw that you are trying to use docker-ce? If so, can you try to use the 2.0.0 version of the plugin and see if that addresses the issue or if this issue still remains? I'm very curious.

I didn't write any new code for systemd, but I did make sure that config.json via this link https://docs.docker.com/network/proxy/ is supported as shown in the docs.

If I understand the docker documentation correctly ensuring that the associated ENV variables for HTTP_PROXY and HTTPS_PROXY should also work as long as the docker-ce service has been restarted after those vars are set in the environment for that particular user.

Anyway, looking forward to hearing from you and hope that the new version of this plugin addressed this request.

codylane commented 5 years ago

Hello - Have you guys had a chance to try out the 2.0.0 version of the plugin? I fairly confident I've addressed both problems.

I should also be releasing 2.0.1 very soon which will address few more outstanding issues. If I don't hear from you by the end of next week then I'll assume this is no longer a problem and i'll close out this issue.

wangkexiong commented 5 years ago

vagrant-proxyconf did MAKE /etc/sysconfig/docker based on your configuration. But docker-ce under systemd does NOT read this file. Hope this can be added in latest version.

Workaround: (Add following in your provisioning script in Vagrantfile)

HACK for docker-ce proxyconf

mkdir -p /etc/systemd/system/docker.service.d cat <<-EOF > /etc/systemd/system/docker.service.d/http-proxy.conf [Service] EnvironmentFile=-/etc/sysconfig/docker EOF

codylane commented 5 years ago

2.0.1 has been released. Please re-open if this is still an issue.

antoinetran commented 5 years ago

Hi @codylane ,

I cannot reopen this but this is still an issue. My env:

There are two issues:

  1. I start Vagrant from official centos/7:1803.1 image, that does not contains docker. vagrant proxyconf will not set proxy conf for docker because, docker is not installed yet. I install docker inside, but is-here a way to force the proxy conf even if docker is not installed? Workaround: I would have to do vagrant reload.
  2. Even if I do vagrant reload, Vagrant creates a /etc/sysconfig/docker and /etc/docker/config.json, with http proxy configured. But docker-ce, both 17.12.1 and latest 18.09.6, does not read the two files. The docker official instructions for http proxy is https://docs.docker.com/config/daemon/systemd/ , with systemd unit file, and this works. This should be the way proxyconf sets the docker proxy.
codylane commented 5 years ago

Hi @antoinetran - Thank you for reporting this issue and getting back to me. Also thank you for your very detailed description of the problem and how I may reproduce this issue and or how I may attempt a fix for this issue. I realize now that this has been going on for some time and I hope that we are able to resolve it soon.

With that said, I don't have a lot of free time right now but I do know how to fix this now. I'll likely end up writing the feature i'll create some tests for it but I'd like to ask if you guys could help me validate it works for you since I don't have a windows box that I can use easily. Would that be ok with you?

Thanks again for reporting and I look forward to working with you to resolve this issue. I should have some free time in the next couple of weeks to address.

antoinetran commented 5 years ago

@codylane no problem!

Also, for other people, until the final fix, here is a clean workaround: In $HOME/vagrant.d/Vagrantfile:

Vagrant.configure("2") do |config|
  if Vagrant.has_plugin?("vagrant-proxyconf")
    config.proxy.http     = "http://IP:8080/"
    config.proxy.https    = "http://IP:8080/"
    config.proxy.no_proxy = "localhost,127.0.0.1,.example.com"
  end

  if ENV.has_key?('http_proxy')
   HTTP_PROXY = ENV['http_proxy']

   # https://www.vagrantup.com/docs/provisioning/basic_usage.html
   config.vm.provision "shell", 
    preserve_order: true,
    inline: <<-SHELL

      mkdir -p /etc/systemd/system/docker.service.d
      echo '[Service]' > /etc/systemd/system/docker.service.d/http-proxy.conf
      echo 'Environment="HTTP_PROXY=#{HTTP_PROXY}"' >> /etc/systemd/system/docker.service.d/http-proxy.conf
    SHELL
  end
end
codylane commented 5 years ago

Friendly update as promised. I've not had any free cycles to look into this and I apologize. I hope to get to this soon like in the next week or so. Thanks again for your patience and for reporting.

antoinetran commented 5 years ago

Hi @codylane , no need to hurry, the workaround works well until the final fix.

codylane commented 5 years ago

Currently staging the 2.0.2 release which I hope addresses this issue. I'd love to have some feedback once I merge this PR into this repository. I'll respond once I merge this PR into this repository.

codylane commented 5 years ago

PR has been merged, if you are able would you mind testing this before I cut a new release? I'm hoping the instructions README.md here are good enough for your testing.

here's the gist of it

Development version from git repository:

git clone https://github.com/tmatilai/vagrant-proxyconf.git
cd vagrant-proxyconf

# Optionally check out other than the master branch
git checkout <branch>

# If you don't have Ruby installed, you can use <path/to/vagrant>/embedded/bin/gem>.
# If you have Docker you can use the Ruby image:
# docker run -it --rm -v ${PWD}:/usr/src/myapp -w /usr/src/myapp ruby:2.6 gem build vagrant-proxyconf.gemspec
gem build vagrant-proxyconf.gemspec

vagrant plugin install vagrant-proxyconf-*.gem
remingtonc commented 5 years ago

@codylane This is exactly what I was debugging thinking it was in the latest release :) Given it's in master, is it reasonable to cut an early release as a gem?

codylane commented 5 years ago

hey @remingtonc - I appreciate your response and I'm sorry to hear that you spent some time debugging the issue. I probably should have just released it. With that said, I'll do that right now.

If you don't mind after it's released I would love some feedback if it's working or if there are different problems. I won't lie our tests don't cover every possible use case and sometimes it causes some regressions which is why I was waiting to release.

codylane commented 5 years ago

Release 2.0.2 to RubyGems and Github.

I'll leave this issue open for folks to comment. I'll close it out on 8-1-2019 if there are no further responses. Happy Friday!

antoinetran commented 5 years ago

Installation not yet present if I explicitly install 2.0.2. I had to download gem files:

user@host MINGW64 /t/Data/VM
$ vagrant plugin install vagrant-proxyconf
==> vagrant: A new version of Vagrant is available: 2.2.5 (installed version: 2.2.3)!
==> vagrant: To upgrade visit: https://www.vagrantup.com/downloads.html

Installing the 'vagrant-proxyconf' plugin. This can take a few minutes...
Installed the plugin 'vagrant-proxyconf (2.0.1)'!

user@host MINGW64 /t/Data/VM
$ vagrant plugin install vagrant-proxyconf 2.0.2
Installing the 'vagrant-proxyconf' plugin. This can take a few minutes...
Installed the plugin 'vagrant-proxyconf (2.0.1)'!
Installing the '2.0.2' plugin. This can take a few minutes...
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:

Unable to resolve dependency: user requested '2.0.2 (> 0)'

user@host MINGW64 /t/Data/VM
$ vagrant plugin install /t/Downloads/vagrant-proxyconf-2.0.2.gem
Installing the 'T:/Downloads/vagrant-proxyconf-2.0.2.gem' plugin. This can take a few minutes...
Successfully uninstalled vagrant-proxyconf-2.0.1
Installed the plugin 'vagrant-proxyconf (2.0.2)'!

Now if I vagrant up an image without docker, and install docker in it, the proxyconf does nothing (normal) until I do vagrant reload. Then the docker conf is created and docker works normally.

So it seems to work fine for me! I will still keep my workaround, because I install docker after the proxyconf checks for its presence. Thank you.

antoinetran commented 5 years ago

Just a question: is the proxy conf file for docker cleaned somehow, or does it stay indefinitely? I mean, if I do vagrant up in a corporate environment, and transfer my VM in an env without proxy, does the file stay? Thank you.

codylane commented 5 years ago

Installation not yet present if I explicitly install 2.0.2. I had to download gem files:

user@host MINGW64 /t/Data/VM
$ vagrant plugin install vagrant-proxyconf
==> vagrant: A new version of Vagrant is available: 2.2.5 (installed version: 2.2.3)!
==> vagrant: To upgrade visit: https://www.vagrantup.com/downloads.html

Installing the 'vagrant-proxyconf' plugin. This can take a few minutes...
Installed the plugin 'vagrant-proxyconf (2.0.1)'!

user@host MINGW64 /t/Data/VM
$ vagrant plugin install vagrant-proxyconf 2.0.2
Installing the 'vagrant-proxyconf' plugin. This can take a few minutes...
Installed the plugin 'vagrant-proxyconf (2.0.1)'!
Installing the '2.0.2' plugin. This can take a few minutes...
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:

Unable to resolve dependency: user requested '2.0.2 (> 0)'

user@host MINGW64 /t/Data/VM
$ vagrant plugin install /t/Downloads/vagrant-proxyconf-2.0.2.gem
Installing the 'T:/Downloads/vagrant-proxyconf-2.0.2.gem' plugin. This can take a few minutes...
Successfully uninstalled vagrant-proxyconf-2.0.1
Installed the plugin 'vagrant-proxyconf (2.0.2)'!

Now if I vagrant up an image without docker, and install docker in it, the proxyconf does nothing (normal) until I do vagrant reload. Then the docker conf is created and docker works normally.

So it seems to work fine for me! I will still keep my workaround, because I install docker after the proxyconf checks for its presence. Thank you.

Hi @antoinetran - I think you might be looking for vagrant plugin update not vagrant plugin install the install doesn't have an upgrade feature. However, that said, you can install a specific version using vagrant plugin install vagrant-proxyconf --plugin-version 2.0.1

$ vagrant plugin update vagrant-proxyconf
Updating plugins: vagrant-proxyconf. This may take a few minutes...
Fetching: vagrant-proxyconf-2.0.2.gem (100%)
Successfully uninstalled vagrant-proxyconf-2.0.1
Updated 'vagrant-proxyconf' to version '2.0.2'!

I'm sorry to hear that you are still having some issues with this plugin. I'm wondering if you can help with the following?

I was using this environment for testing the 2.0.2 integration. I should also say that there are many, many different code paths for configuring docker depending on which box you are using and I'm not sure I've covered all of them as I was only testing centos/7 with the docker provisioner behind a proxy.

The downside of how this is all implemented is due to a very complex middleware that Vagrant uses and I'm still not sure I completely understand how it all works. I've tried to address those as I have spare time but i'm not so sure I've covered every possible edge condition and because this plugin attempts to be backwards compatible I try to keep changes small.

It could entirely be possible that we have a chicken and egg problem here and a reload or provision is needed a second time because of the way the middleware hooks are implemented in this plugin. I'll see if I can come up with something to address this.

codylane commented 5 years ago

Just a question: is the proxy conf file for docker cleaned somehow, or does it stay indefinitely? I mean, if I do vagrant up in a corporate environment, and transfer my VM in an env without proxy, does the file stay? Thank you.

No problem and it's a good question. I believe I've addressed this as well and the any proxy is configured it will attempt to unconfigure it if you choose to disable it. That said, the README explains this in more detail. If it's confusing let me know.

codylane commented 5 years ago

Hi @antoinetran - I just cut 2.0.3 which I hope addresses the issue when docker doesn't exist in the box upon first run, the provisioner should run after docker installed so you don't have to run vagrant provisionor vagrant reload now. (Crossing fingers) . Let me know.

antoinetran commented 5 years ago

I'm sorry to hear that you are still having some issues with this plugin. I'm wondering if you can help with the following?

* Can you send me a `Vagrantfile` snippet that you are using?

See below.

* Can you send what host OS and version you are using?

Windows 10

* Can you tell me which version of Vagrant you are using again?

Installed Version: 2.2.3

* I'd also like to know which vagrant box you are using and version?

See below: centos/7:1803.01

I am not sure what you did, but I find it normal that I had to reload, because the proxyconf works either before or after box specific command lines, in this case install-docker.sh. If it is before, the proxyconf will do nothing as docker is not installed yet. If after, the proxyconf will do its job but, the install-docker.sh launches a test by pulling hello-world docker image. Without proxyconf, it will not work too.

Unless there is a way to force proxyconf even if docker is not installed, or a way to install docker, then do proxyconf, then do post install stuff (like hello-world), I do not see another way here. The workaround I posted (explicitely do the proxyconf job in ~/.vagrant.d/Vagrantfile) works enough for me, though.

Vagrantfile used:

required_plugins = %w(vagrant-disksize)

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.box_version = "1803.01"
  #config.disksize.size = '20GB'
  config.vm.provision :shell, path: "install-docker.sh"

  config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
     vb.gui = true
     vb.customize ["modifyvm", :id, "--accelerate2dvideo", "on"]
     vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
     vb.customize ["modifyvm", :id, "--vram", "128"]
  #
  #   # Customize the amount of memory on the VM:
     vb.memory = "4096"
     vb.cpus = 2
  end
end
$ cat install-docker.sh
#!/usr/bin/env bash

# Install Docker on CentOS 7 per
# https://docs.docker.com/engine/installation/linux/docker-ce/centos/

set -e # Exit if any subcommand fails
set -x # Print commands for troubleshooting

# 1. Install required packages.

sudo yum install --assumeyes --quiet yum-utils \
  device-mapper-persistent-data \
  lvm2

# 2. Use the following command to set up the stable repository. You always need the stable repository, even if you want to install builds from the edge or test repositories as well.

sudo yum-config-manager --quiet \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

# 3. Optional: Enable the edge and test repositories.

# yum-config-manager --enable docker-ce-edge
# yum-config-manager --enable docker-ce-test

# INSTALL DOCKER CE

# Update: install only the target version of docker.
# 1. Install the latest version of Docker CE

sudo yum install --assumeyes --quiet docker-ce-17.12.1.ce-1.el7.centos.x86_64

# 3. Start Docker. Report if it failed.

sudo systemctl start docker || sudo systemctl status docker.service

# 4. Verify that docker is installed correctly by running the hello-world image.

sudo docker run --rm hello-world

# Post-installation steps for Linux, per
# https://docs.docker.com/engine/installation/linux/linux-postinstall/

# Configure Docker to start on boot
sudo systemctl enable docker
codylane commented 5 years ago

Thanks for the info, just curious which version of 'vagrant-proxyconf' do you have installed? I've made a few updates in the past few days that may resolve this issue in the lastest release. I'll be cutting 2.0.5 in the next day or so.

antoinetran commented 5 years ago

Thanks for the info, just curious which version of 'vagrant-proxyconf' do you have installed? I've made a few updates in the past few days that may resolve this issue in the lastest release. I'll be cutting 2.0.5 in the next day or so.

$ vagrant plugin list
vagrant-proxyconf (2.0.2, global)
  - Version Constraint: 2.0.2
vagrant-vbguest (0.18.0, global)
vagrant-vbguest-centos (0.2.0, global)
codylane commented 5 years ago

Thanks, please try upgrading the the latest version which should be 2.0.4. I just checked and 2.0.2 doesn't contain the fix you are looking for. I apologize for the confusion.

codylane commented 5 years ago

No further issues have been reported for this issue. If there are still problems please make sure you have upgraded to the 2.0.4 release which includes a few additional fixes for systemd + docker.

Closing out this issue since 2.0.2 has been released and no further issues have been reported.

antoinetran commented 5 years ago

I have updated plugin:

$ vagrant plugin list
vagrant-proxyconf (2.0.5, global)
  - Version Constraint: > 0
vagrant-vbguest (0.18.0, global)
  - Version Constraint: > 0
vagrant-vbguest-centos (0.2.0, global)
  - Version Constraint: > 0

I restarted the test, with a base box centos 7, without docker, and a script that installs docker inside at startup. As I said, I expected the error below: the proxyconf did nothing because it did not find docker inside / or because it waited the custom script's end, and unfortunately, the it doesn't end well if docker cannot pull from registry. Anyways, it does not matter to me, it is difficult to handle this scenario, unless do as I said: either an option to force docker proxyconf, or a way to separated install docker , proxyconf, and docker run.

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/7' version '1803.01' is up to date...
==> default: Setting the name of the VM: centos-7-v180301_default_1564402019863_74048
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (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:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Configuring proxy environment variables...
==> default: Configuring proxy for Yum...
[default] No Virtualbox Guest Additions installation found.
...
...
Copy iso file C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
Mounting Virtualbox Guest Additions ISO to: /mnt
mount: /dev/loop0 is write-protected, mounting read-only
Installing Virtualbox Guest Additions 6.0.0 - guest version is unknown
Verifying archive integrity... All good.
Uncompressing VirtualBox 6.0.0 Guest Additions for Linux........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.  This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: Building the modules for kernel 3.10.0-693.21.1.el7.x86_64.
VirtualBox Guest Additions: Starting.
Redirecting to /bin/systemctl start vboxadd.service
Redirecting to /bin/systemctl start vboxadd-service.service
Unmounting Virtualbox Guest Additions ISO from: /mnt
==> default: Checking for guest additions in VM...
==> default: Rsyncing folder: /cygdrive/t/Data/VM/centos-7-v1803.01/ => /vagrant
==> default: Running provisioner: shell...
    default: Running: C:/Users/atran/AppData/Local/Temp/vagrant-shell20190729-11616-7tcwyu.sh
    default: + sudo yum install --assumeyes --quiet yum-utils device-mapper-persistent-data lvm2
    default: Package yum-utils-1.1.31-42.el7.noarch already installed and latest version
    default: Package device-mapper-persistent-data-0.7.0-0.1.rc6.el7_4.1.x86_64 already installed and latest version
    default: Package 7:lvm2-2.02.171-8.el7.x86_64 already installed and latest version
    default: + sudo yum-config-manager --quiet --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    default: adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
    default: grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
    default: repo saved to /etc/yum.repos.d/docker-ce.repo
    default: + sudo yum install --assumeyes --quiet docker-ce-17.12.1.ce-1.el7.centos.x86_64
    default: warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-17.12.1.ce-1.el7.centos.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
    default: Public key for docker-ce-17.12.1.ce-1.el7.centos.x86_64.rpm is not installed
    default: Importing GPG key 0x621E9F35:
    default:  Userid     : "Docker Release (CE rpm) <docker@docker.com>"
    default:  Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
    default:  From       : https://download.docker.com/linux/centos/gpg
    default: + sudo systemctl start docker
    default: + sudo docker run --rm hello-world
    default: Unable to find image 'hello-world:latest' locally
    default: docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
    default: See 'docker run --help'.
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
antoinetran commented 5 years ago

It is fine for me that the issue is closed.

codylane commented 5 years ago

hi @antoinetran - I'm sorry to to hear it's still not working for you. I agree this is something that is hard to test for and or come up with a one size solution that fits everyone's use case(s). It's interesting that I see vagrant-proxyconf has configured the yum and environment proxies before your provisioner runs. This is a good sign, but as you describe the issue is that you are trying to install docker with your own custom provisioner + attempting to orchestrate the setup before docker is completely managed by vagrant-proxconf.

I think I see what the problem is now and to from all examples that you have provided it's an issue with how your provisioner is written. Assuming that you are still using this file

$ cat install-docker.sh
#!/usr/bin/env bash

# Install Docker on CentOS 7 per
# https://docs.docker.com/engine/installation/linux/docker-ce/centos/

set -e # Exit if any subcommand fails
set -x # Print commands for troubleshooting

# 1. Install required packages.

sudo yum install --assumeyes --quiet yum-utils \
  device-mapper-persistent-data \
  lvm2

# 2. Use the following command to set up the stable repository. You always need the stable repository, even if you want to install builds from the edge or test repositories as well.

sudo yum-config-manager --quiet \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

# 3. Optional: Enable the edge and test repositories.

# yum-config-manager --enable docker-ce-edge
# yum-config-manager --enable docker-ce-test

# INSTALL DOCKER CE

# Update: install only the target version of docker.
# 1. Install the latest version of Docker CE

sudo yum install --assumeyes --quiet docker-ce-17.12.1.ce-1.el7.centos.x86_64

# 3. Start Docker. Report if it failed.

sudo systemctl start docker || sudo systemctl status docker.service

# 4. Verify that docker is installed correctly by running the hello-world image.

sudo docker run --rm hello-world

# Post-installation steps for Linux, per
# https://docs.docker.com/engine/installation/linux/linux-postinstall/

# Configure Docker to start on boot
sudo systemctl enable docker

It's as you as you describe, the issue is caused because of a chicken and egg problem. You are trying to use docker before vagrant-proxyconf know's that it is installed. To work around this you would need to remove everything past step 3 so that you are only installing docker upon the first run, otherwise, you would have to remember to configure all the proxy configuration for docker prior to trying to download images or use docker.

Example:

$ cat install-docker.sh
#!/usr/bin/env bash

# Install Docker on CentOS 7 per
# https://docs.docker.com/engine/installation/linux/docker-ce/centos/

set -e # Exit if any subcommand fails
set -x # Print commands for troubleshooting

# 1. Install required packages.

sudo yum install --assumeyes --quiet yum-utils \
  device-mapper-persistent-data \
  lvm2

# 2. Use the following command to set up the stable repository. You always need the stable repository, even if you want to install builds from the edge or test repositories as well.

sudo yum-config-manager --quiet \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

# 3. Optional: Enable the edge and test repositories.

# yum-config-manager --enable docker-ce-edge
# yum-config-manager --enable docker-ce-test

# INSTALL DOCKER CE

# Update: install only the target version of docker.
# 1. Install the latest version of Docker CE

sudo yum install --assumeyes --quiet docker-ce-17.12.1.ce-1.el7.centos.x86_64

This should take care of installing + configuring of docker to work behind a proxy upon first run. Then when you log into the box for the first time your hello world example should work. I've not had a chance to test this but I have a feeling this scenario might work a little better and shouldn't require a reload or second vagrant provision.