Vagrant 1.8.5
OS X El Capitan 10.11.6
CentOS 6
Vagrant.configure("2") do |config|
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
config.vm.provider "docker" do |d|
d.image = "monkeyswithbuttons/docker-vagrant-centos6"
d.has_ssh = true
d.remains_running = true
d.force_host_vm = false
end
(1..2).each do |machine_id|
machine_name = "machine-%02d" % machine_id
config.vm.define machine_name do |machine|
machine.vm.hostname = machine_name
end
end
end
https://gist.github.com/geogdog/419a1cac137dff1abbb93819a311cfdd
Vagrant makes an ssh connection and completes an _up_
Vagrant hangs trying to make a connection to the 172.17.0.0/24 address but the routing fails. Creating a manual ssh connection to the locally forwarded port works fine: ssh -l vagrant 127.0.0.1:2222.
Create an option to force the use of the locally forwarded ssh ports?
vagrant upNone
I experienced the same issue ( with Mac OSX El Capitan, vagrant 1.8.5, Docker for Mac version 1.12.0 (build: 10871) )
Looking at the output of inspect I see one place where the host/port is correct:
"Ports": {
"22/tcp": [
{
"HostIp": "127.0.0.1",
"HostPort": "2222"
}
]
},
and quickly checking using this
network = driver.inspect_container(@machine.id)['NetworkSettings']
sshport = network['Ports']['22/tcp'][0]
return {
host: sshport['HostIp'],
port: sshport['HostPort'],
}
to replace the existing use of IPAddress and @machine.config.ssh.guest_port makes vagrant ssh work for me.
Mind you I've no idea how brittle that is, works with a sample size of one with a trivial Vagrantfile.
It would be great to wrap this if a conditional for the docker provider configuration:
if @machine.provider_config.force_local_ssh
...
Assuming the current code is working with boot2docker, if there's a conditional could it be simply based on force_host_vm? (Which should probably have a default of false these days I guess?)
(Rather than requiring most everyone to set the unbreak_me = :pretty_please option I'd hope there's a way to make vagrant to do the right thing _by default_ and perhaps provide a i_know_what_im_doing = true options for the more advanced network configurations.)
We're experiencing this as well, would be great if there was a flag to make sure it uses localhost to connect.
This workaround works fine for me.
Vagrant.configure("2") do |config|
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
config.vm.provider "docker" do |d|
d.image = "monkeyswithbuttons/docker-vagrant-centos6"
d.has_ssh = true
d.remains_running = true
d.force_host_vm = false
end
(1..2).each do |machine_id|
machine_name = "machine-%02d" % machine_id
config.vm.define machine_name do |machine|
machine.vm.hostname = machine_name
machine.vm.network "forwarded_port", guest: 22, host: 2200 + machine_id, id: 'ssh'
machine.ssh.host = "localhost"
machine.ssh.port = 2200 + machine_id
end
end
end
As much as we all love a good work around, it doesn't work for me as I have multiple vagrant projects running at once so my ports don't necessarily start at 2200.
The configuration solution I really think is the most viable here.
@geogdog Agree, on configuration solution. The workaround was just an idea and it might be useful.
I experienced the same issue, and @tko 's workaround works fine for me .
@pstengel , #7840 has not merged to master so far, had to apply manually.
Until #7840 or similar is merged I'm using the following (replace the asterisk with the machine name in the case you're running multiple machines in the same Vagrantfile):
config.vm.provider "docker" do |d, override|
d.force_host_vm = false
d.has_ssh = true
override.ssh.host = "127.0.0.1"
override.ssh.port = `head -n1 .vagrant/machines/*/docker/id | xargs docker inspect | grep -n3 '22/tcp' | grep 'HostPort' | head -n1 | perl -pe 's/.+?"([0-9]+)".*/\\1/'`.chop
end
I am really keen on this issue to be solved and PR #7840 to be merged.
Should this have been already fixed in 1.8?
Fixed via #7840
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.