Closed ghost closed 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.
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
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.
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.
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)
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
2.0.1 has been released. Please re-open if this is still an issue.
Hi @codylane ,
I cannot reopen this but this is still an issue. My env:
There are two issues:
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.
@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
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.
Hi @codylane , no need to hurry, the workaround works well until the final fix.
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.
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
@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?
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.
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!
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.
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.
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?
Vagrantfile
snippet that you are using? 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.
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.
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 provision
or vagrant reload
now. (Crossing fingers) . Let me know.
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
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.
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)
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.
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.
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.
It is fine for me that the issue is closed.
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
.
I expect that proxy is set for docker, but is not.
Versions
Vagrantfile
Here's the test with output:
default: Environment=
equal to "" so far so good, but when doingis still
and i expect
see: https://docs.docker.com/config/daemon/systemd/#httphttps-proxy