1

~/.ssh/my_id_rsa in a VM created by docker-machine create gets disappeared whenever I restart it. I've read documents on docs.docker.com, but I couldn't find information about this issue.

My host machine is Mac (El Capitan), and the version of docker-machine is as follows:

$ docker-machine version
docker-machine version 0.6.0, build e27fb87

I've created my VM with following options:

$ docker-machine create --driver virtualbox dev

Is there any advice on how to fix this issue? Where should I look into?

More concretely, I want to know how to avoid this issue:

(host) $ docker-machine create --driver virtualbox dev
(host) $ docker-machine ssh dev
(dev) $ ssh-keygen
...
(dev) $ ls ~/.ssh
authorized_keys   authorized_keys2  id_rsa            id_rsa.pub
(dev) $ logout
(host) $ docker-machine restart dev
(host) $ docker-machine ssh dev
(dev) $ ls ~/.ssh
authorized_keys   authorized_keys2

Where's "id_rsa" and "id_rsa.pub"?

aeas44
  • 27
  • 6

1 Answers1

2

Usually, I don't specify anything regarding ssh keys: docker-machine creates a passphrase-less ssh key in ~/.docker/machine/machines/<amachine>/

If you want to specify your own, see this example from the docker-machine documentation:

$ docker-machine create \
  --driver generic \
  --generic-ip-address=203.0.113.81 \
  --generic-ssh-key=~/.ssh/id_rsa \
  vm

The OP adds:

(dev) $ logout
(host) $ docker-machine restart dev
(host) $ docker-machine ssh dev

That is creating ssh key within the virtual machine itself: the TinyCore-based boot2docker only persists what is in /var/lib/boot2docker, nothing else.
It does mount /Users, but other than that, anything else (including /home/docker, the ~ in ~/.ssh)is reset to the boot2docker.iso original content at the next restart.
See "boot2docker: Persist data"

For those ssh keys to persists across session, you would need to either:

  • generate them in /Users/any/path/you/want (as they would actually be stored on the host)
  • or generate them in /var/lib/boot2docker
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I understand you don't want to specify your key. I am just saying your key should not be involved at all by a docker-machine create command, as docker-machine manages its own set of keys. – VonC Mar 26 '16 at 07:35
  • Hmm, ok. It makes sense. But do you know the reason why "docker-machine restart" deletes my key? (I've added "More concretely..." section to the question) – aeas44 Mar 26 '16 at 07:39
  • @aeas44 I just read your "more concretely" section of your question, and I have edited my answer accordingly. Generating your ssh key *within* the VM is something I had missed initially. – VonC Mar 26 '16 at 08:16
  • Thx @VonC! I didn't know that data in boot2docker is basically ephemeral except for things in /var/lib/boot2docker. It's exactly what I wanted to know! – aeas44 Mar 26 '16 at 14:03
  • @aeas44 Yes, I use /var/lib/boot2docker to put scripts I want to persists, like one setting a fixed IP address for the machine at each reboot: http://stackoverflow.com/a/36130098/6309 – VonC Mar 26 '16 at 14:05