Docker can't connect to boot2docker because of TCP timeout

Osx MavericksDockerBoot2docker

Osx Mavericks Problem Overview


I'm running Mac OS 10.9.5 (Mavericks), I've followed https://docs.docker.com/installation/mac/ to install Docker. I get a timeout error message when I run Docker even though the boot2docker VM is running in the background.

nikhil@macbook ~> boot2docker status
running
nikhil@macbook ~> boot2docker ip

The VM's Host only interface IP address is: 192.168.59.103

nikhil@macbook ~> docker run hello-world
2014/11/01 01:01:31 Post https://192.168.59.103:2376/v1.15/containers/create: dial tcp 192.168.59.103:2376: i/o timeout
nikhil@macbook ~> docker search ubuntu
2014/11/01 01:02:40 Get https://192.168.59.103:2376/v1.15/images/search?term=ubuntu: dial tcp 192.168.59.103:2376: i/o timeout

I have verified that Docker is running inside the boot2docker VM and that my port is correct.

nikhil@macbook ~> boot2docker ssh
                        ##        .
                  ## ## ##       ==
               ## ## ## ##      ===
           /""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
           \______ o          __/
             \    \        __/
              \____\______/
 _                 _   ____     _            _
| |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.3.1, build master : 9a31a68 - Fri Oct 31 03:14:34 UTC 2014
Docker version 1.3.1, build 4e9bbfa
docker@boot2docker:~$ sudo netstat -ntpl | grep docker
tcp        0      0 :::2376                 :::*                    LISTEN      629/docker

Osx Mavericks Solutions


Solution 1 - Osx Mavericks

I am using OS X v10.10 (Yosemite) and Cisco Anyconnect (which are apparently a bad combination for using boot2docker), and the following finally worked for me (thanks to the linked GitHub issue comment):

These steps will add a port forwarding rule and modify your environment to have Docker point to 127.0.0.1 (instead of 192.168.59.103 or other NATed IP address).

First - boot2docker needs to be installed, but not running.

If it is currently running - stop it now:

boot2docker down

Add a rule to forward traffic from 127.0.0.1:2376 to port 2376 on the boot2docker vm:

vboxmanage modifyvm "boot2docker-vm" --natpf1 "docker,tcp,127.0.0.1,2376,,2376"

Start boot2docker:

boot2docker up

Set default DOCKER environment variables:

$(boot2docker shellinit)

Override the DOCKER_HOST variable to point to 127.0.0.1:

export DOCKER_HOST=tcp://127.0.0.1:2376

Now you should be able to run docker commands:

docker version

Solution 2 - Osx Mavericks

I have had this issue as well and here is a temporary solution.

First, open VirtualBox and check the network settings on the boot2docker VM to see what the host only adapter is named. In my case, it's vboxnet1; for you, it may be vboxnet0.

Then, apply this command:

sudo route -nv add -net 192.168.59 -interface vboxnet1

Now you should be able to run Docker commands.

See this issue for more information.

I am noticing over time that a common denominator in this problem is Cisco anyconnect (me included), for what it's worth.

Solution 3 - Osx Mavericks

Here's what I did to fix the issue (I use OS X v10.10 (Yosemite) and the accepted answer didn't work for me):

  • boot2docker delete - Warning: this deletes all your Docker images.
  • In VirtualBox, go to VirtualBox (menu) → Preferences → Network → Host Only Networks
  • Delete the host only networks, and then I re-added them
  • boot2docker init
  • boot2docker up

Now Docker works from the OS X command line via iTerm2 for me.

Solution 4 - Osx Mavericks

This happened to me as well, and none of the previous answers fixed the problem.

Today, thanks to a colleague's suggestion, I did not startup my VPN connection first. I rebooted my machine, and started with Docker from the beginning.

boot2docker init
boot2docker up
$(boot2docker shellinit)
docker run hello-world

It worked as expected!

I found this post by Florian Rosenberg useful. I read through it in detail, but I think most of what he is suggesting in the first part has been factored into the most recent version of boot2docker. But the insightful bit was "Connecting to VPN Things will break".

It suggested to look for a firewall rule that denies any to any. So, without VPN fired up I looked for this rule, and it was not there. Sure enough, once I fired up my VPN, I got the following (different) error...

docker run hello-world
2014/11/13 11:11:18 Post https://192.168.59.103:2376/v1.15/containers/create: dial tcp 192.168.59.103:2376: permission denied

I checked the firewall rules, and sure enough a new rule was added...

sudo ipfw -a list | grep "deny ip"
00411    1      64 deny ip from any to any 

Once I removed that firewall rule with:

sudo ipfw delete 00411

I was able to talk to Docker from the OS X command shell.

Solution 5 - Osx Mavericks

OK, so this happened to me as well.

First of all, setting the environment variables is necessary. But then, I kept getting the I/O timeout error even after that.

So, instead of starting boot2docker by running the application package (clicking on the boot2docker icon), I started it from the command line.

I first executed,

$boot2docker init

This said, the VM was already running.

Then I went ahead and tried to start it.

$boot2docker start

This started it.

You can verify it by running

$boot2docker info

It prints a JSON about your running instance.

Then, you can ssh into it and run

$boot2docker ssh
$docker run hello-world

That's it.

Solution 6 - Osx Mavericks

I had this issue after running Cisco AnyConnect. Even after I shut down AnyConnect, the issue persisted.

@treehau5's answer works, but doing boot2docker poweroff, and then using Activity Monitor, kill the ciscod left behind by AnyConnect also worked for me. Then I opened a new Terminal window and started boot2docker normally and Docker commands then worked fine.

Solution 7 - Osx Mavericks

It was easy for me. I upgraded VirtualBox and this problem went away.

Solution 8 - Osx Mavericks

I tried treehau5's method, but it did not work. I changed VirtualBox's Network setting of boot2docker VM setting - 'host-only Adapter's Promiscuous mode to 'Allow All'.

Solution 9 - Osx Mavericks

I removed vboxnet0 from VirtualBox preferences and initialized a second boot2docker VM (boot2docker --vm="boot2docker-vm2" init) to recreate vboxnet0 with the correct settings.

After this, things seemed to be back to normal.

Solution 10 - Osx Mavericks

Here's what worked for me when I hit a similar snag. Make sure you've upgraded VirtualBox, then:

  1. boot2docker stop
  2. boot2docker init
  3. boot2docker start; eval "$(boot2docker shellinit)"

Then, just for sanity's sake, check that $DOCKER_HOST matches $(boot2docker ip). I suspect I had many things going on, as when I first started, $DOCKER_HOST had become unset somehow.

The issue and some discussion can be found in the GitHub issues page here - it does rather seem as if it's often just a case of VirtualBox being flaky.

Solution 11 - Osx Mavericks

Check your DOCKER_HOST environment variable. It should be pointing to:

export DOCKER_HOST=tcp://192.168.59.103:2376

Solution 12 - Osx Mavericks

In my case I just had to restart my Mac host machine and the problem was gone! I was not connected to VPN or anything of that sort. I am not sure of the reason why this happened.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnikhilView Question on Stackoverflow
Solution 1 - Osx Mavericksuser2472759View Answer on Stackoverflow
Solution 2 - Osx MavericksdarethasView Answer on Stackoverflow
Solution 3 - Osx MavericksKLawView Answer on Stackoverflow
Solution 4 - Osx MavericksbobbiejcView Answer on Stackoverflow
Solution 5 - Osx Maverickswlan0View Answer on Stackoverflow
Solution 6 - Osx MavericksDan TenenbaumView Answer on Stackoverflow
Solution 7 - Osx MavericksRimianView Answer on Stackoverflow
Solution 8 - Osx MaverickssurajzView Answer on Stackoverflow
Solution 9 - Osx MaverickslennyView Answer on Stackoverflow
Solution 10 - Osx MavericksAlex LynhamView Answer on Stackoverflow
Solution 11 - Osx MavericksAshish JuyalView Answer on Stackoverflow
Solution 12 - Osx MavericksChaitanyaBhattView Answer on Stackoverflow