JonasProgrammer / docker-machine-driver-hetzner

Docker machine driver for the new hetzner cloud API
https://jonasprogrammer.github.io/docker-machine-driver-hetzner/
MIT License
431 stars 53 forks source link

Server not found after recreating docker machine from Hetzner snapshot #42

Closed jasdhfjhq2412341234 closed 4 years ago

jasdhfjhq2412341234 commented 4 years ago

Hi, I created machine snapshot using Hetzner cloud console. Then I deleted the machine and recreated it from snapshot. The IP did not change. Still I receive:

MacBook-Pro:platform slava$ docker-machine --debug ssh platform
Docker Machine Version:  0.16.2, build bd45ab13
Found binary path at /usr/local/bin/docker-machine-driver-hetzner
Launching plugin server for driver hetzner
Plugin server listening at address 127.0.0.1:49804
() Calling .GetVersion
Using API Version  1
() Calling .SetConfigRaw
() Calling .GetMachineName
(platforma) Calling .GetState
server not found

Could you please advise how to fix the issue? I can login the server and can verify that docker is running and all containers are started.

JonasProgrammer commented 4 years ago

Hi,

sorry for responding only now.

By 'deleted the machine and recreated it' you mean doing so from the Hetzner cloud control panel (or, in general, without using docker-machine)? If so, then the behavior you describe is correct, I'm afraid.

The underlying issue is this: GetState() tries to call the hcloud API using the original cloud instance's id, which does not exist anymore, because you deleted it; a new ID is assigned to the instance, even if it is created from a snapshot and retains its original IP. This in turn leads to the call failing and docker-machine crashing before even trying to connect to the server.

For your specific problem, you can either use your system's ssh client and look up the identity file for the machine using docker-machine inspect or you can manually edit the machine's config.json and set the server id to the new value.

As for the problem in general, I doubt we can fix this. The call to GetState() before connecting is part of docker-machine's design and filtering machines by ID for GetState() only would be inconsistent with destruction, for example, which for obvious reasons should really go by id. Mixing manual instance deletion/creation and docker-machine is going to lead to problems sooner or later, so the best advice I can give is to take your snapshot, then use docker-machine rm to cleanly delete the instance (or docker-machine rm -f, if you manually deleted it beforehand) and then re-create it from the snapshot using --hetzner-image-id. This will cause reprovisioning, however; if that's a problem, your best guess is to create the new machine using the generic driver, but docker-machine rm etc. will not remove the hetzner instance anymore then.

jasdhfjhq2412341234 commented 4 years ago

Perfect, thanks for detailed response!

I have managed to fix my issue by editing config.json, namely IPAddress and ServerID attributes (I should have guessed), then running

docker-machine regenerate-certs <machine-name>

After this the machine is back again 👍