Docker on Windows – FATA[0021] An error occurred trying to connect

This post is to show how to fix “An error occurred trying to connect: …” error after installing a fresh Docker on Windows:

Docker1So, asuming, you have downloaded the latest Docker for Windows package from this link – You install VirtualBox and other components. You open a VirtualBox manager to see that there is nothing yet created :), then you double click on “Boot2Docker start” icon and you see how a new virtual machine is being created and started:Docker15

Then you run a “docker version” command to make sure everything is normal and you get that connection error.

Docker3This message indicates that there is something wrong with the networking.

If you look inside the Linux VM [ifconfig] you will see that it is configured with the same IP address as the docker client is trying to knock in, so should be fine on that side. Lets look at how the overall VirtualBox virtual networking is configured, go to File -> Preferences -> Network:

Docker7Docker4As you can see NAT isn’t setup but on the “Host-only Networks” there are several NICs and one of them [#2] is within the same subnet as the Linux IP.

Lets look at the host [my laptop] routing configuration. Does it know where to send packets for the 192.168.59.x subnet? Run “route print”:

Docker9As you can see the route does exist. All the packets for the destinations will be sent to the interface [VirtualBox interface]. .3 is a lovely choise for a gateway isn’t it 🙂

OK, what about the VM network settings? There are two network adapters configured. First one is set as NAT [we know that NAT is not configured]:

Docker5Another is set to “Host-only Adapter”:

Docker6But look at the number selected. It’s not the adapter that is linked to the 192.168.59.x subnet. Let’s change it to #2 and try “docker version” command again:

Docker8Hey, it works 🙂 But wait a minute. How did the Linux machine gets the IP address? It is not static, it’s been given via DHCP. VirtualBox NIC #3 is configured with the DHCP scope. So if you reboot the VM it’s not going to get an IP address and we suck again. To fix that issue we need to create a DHCP scope on #2:

Docker11Before doing so I have also disabled DHCP on NIC #3.

Now if you reboot, it should work.

If you wonder how Docker Client knows that the IP address of a VM is, then you are with me 🙂 The only thing I was able to figure out is that it’s via “boot2docker.exe ip” command (read the comments below for more):

Docker12But why it returns this exact IP, I do not know. Linux is configured with more then one IP:

Docker13OK, finally we can try running something inside the Docker. There is a tiny image called “hello-world” in the repository online. So if you type “docker run hello-world” you should download it and see the following output:

Docker14That’s it 🙂


4 thoughts on “Docker on Windows – FATA[0021] An error occurred trying to connect

  1. I downloaded docker 1.6.0 for Windows, and hit the same error that you have posted here.
    Inspite of everything, I was not able to get over the FATA[0021] error.
    Then I read the meesage that I could directly run docker or run boot2docker ssh.
    After running boot2docker ssh, the problem got resolved and I could get the docker version to print the values properly

    • Thank you Krishnan.

      Some more about the docker config file:
      The boot2docker binary reads configuration from $BOOT2DOCKER_PROFILE if set, or $BOOT2DOCKER_DIR/profile or $HOME/.boot2docker/profile or (on Windows) %USERPROFILE%/.boot2docker/profile. boot2docker config will tell you where it is looking for the file, and will also output the settings that are in use, so you can initialise a default file to customize using boot2docker config > ~/.boot2docker/profile.

  2. Useful Post Indeed.

    The reason that my IP-connection did throw the same fit as described above was BECAUSE I HAD ACTIVATED MY VPN CONNECTION WITH WORK. The moment I disconnected my VPN, the connection-problem had disappeared (and returned the moment I switched it back on).


Leave a Comment here

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s