Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker unreachable after computer sleep

I have just installed docker using docker-toolbox 1.8.2 on Windows 10.

Due to due to this issue I had to recreate the docker image using these commands

docker-machine rm default
docker-machine --native-ssh create -d virtualbox default

After that it has been working fine, except for one problem:

When the PC has gone to sleep and then wakes again, the docker commands can no longer connect. Example:

> docker images
An error occurred trying to connect: Get https://192.168.99.100:2376/v1.20/images/json: 
dial tcp 192.168.99.100:2376: ConnectEx tcp: A connection attempt failed because the 
connected party did not properly respond after a period of time, or established connection 
failed because connected host has failed to respond.

However the docker-machine lists the machine as running:

> docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM
default   *        virtualbox   Running   tcp://192.168.99.100:2376

I can also confirm in VirtualBox that the VM screen seems to be active.

I have tried starting and stopping the machine, but that does not help

C:\x> docker-machine stop default
C:\x> docker-machine start default
Starting VM...
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
C:\x> docker-machine env default --shell=powershell

Ironically, the last command hangs, so I never get any environment settings.

The only thing that helps is to restart the whole PC. But that should be unnecessary?

I have also posted this as an issue on the docker github repository,but that was closed. A related issue seems to be this one, but no workaround or solution has been posted for Windows.

like image 829
Klas Mellbourn Avatar asked Sep 13 '15 07:09

Klas Mellbourn


4 Answers

Having tried all the other answers here, and having varying but not consistent success, the following seems to reliably bring it back for me after this problem occurs.

Open a powershell/command window (I have most success if I run all docker-machine commands in a powershell window opened as administrator, I don't know if that's important or not) then run (where "dev" is the name of your docker machine instance):

docker-machine ssh dev

Then on the terminal that is opened, run:

sudo shutdown -r now

When the machine restarts, it seems to refresh the network and work correctly. Note, however, that simply running docker-machine restart dev did not have the same effect for me.

Your machine needs to be running before you can do the ssh, so if it's not running, execute docker-machine start dev before trying to SSH.

like image 93
Mark Hughes Avatar answered Sep 20 '22 03:09

Mark Hughes


After hous of fighting with VirtualBox + Docker Toolbox, I finally found the way, how to make Docker working again (even without restarting all the containers):

  1. Wake up PC from sleep
  2. Try docker images (won`t work)
  3. Open VirtualBox -> Close VM with saving state (CTRL+V)
  4. Run your VM again
  5. Try docker images again (now should work)

Please note: All steps are in VirtualBox only! Running docker-machine restart default will create another host-only adapter, which is something you do not want. If you did it anyway, delete all additionally created adapters (File->Preferences->Network on VirtualBox), then follow steps 1-5.

like image 13
Dzoukr Avatar answered Oct 07 '22 17:10

Dzoukr


I have experienced the exact same symptoms on Windows 8.1... The thing is that it's not really a docker-specific issue, but more how Windows manages the VirtualBox network adapters after sleep (I think...). The culprit in my case is that the network adapter's addresses were becoming private after sleep (they became 169.* addresses).

Credits to this guy who gave me the idea: http://lyngtinh.blogspot.ca/2011/12/how-to-disable-autoconfiguration-ipv4.html

Fix:

  1. Start a command prompt as Administrator
  2. Find out the "useful" network adapters: ipconfig /all. The useful ones in my case were the ones labeled "VirtualBox Host-Only Ethernet Adapter" that didn't have private ips (not starting with 169.*).
  3. Run this command and note the "Idx" of the useful VirtualBox network adapters: netsh interface ipv4 show inter.
  4. Run this command to disable the IP auto configuration: netsh interface ipv4 set interface <idx> dadtransmits=0 store=persistent. Replace <idx> with each index found in the previous step.
  5. Restart Windows

Afterwards, I was able to docker-machine start default, then docker-machine env default --shell cmd, put the PC to sleep, wake up and run docker-machine env default --shell cmd again.

like image 6
Jonathan Avatar answered Oct 07 '22 18:10

Jonathan


I found that removing 'host only adapter' (File->Preferences->Network on VirtualBox), and restart the docker-machine helps.

Not a real solution. But probably better over restart the computer.

like image 5
Amir Avatar answered Oct 07 '22 17:10

Amir