vagrant-proxyconf: Proxy doesn't work for Docker with systemd

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

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 29

Commits related to this issue

Most upvoted comments

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.

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

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

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