How to ssh into docker-machine VirtualBox instance?

docker-machine version 0.2.0 docker version 1.6.2

I'm using docker-machine to create a machine using VirtualBox. Everything works fine but I'd like to ssh into the machine itself and I find no instructions on how to do this. I can connect to the ssh port:

ssh $(docker-machine ip dev)

But I've no idea what username / password / identity file to use.


Solution 1:

You can log into docker-machine hosts by just running

docker-machine ssh default

(Using the "default" host here)

The identity files should be stored under ~/.docker/machine/machines. If you want to log into a container (as opposed to the host), use docker exec as suggested by user2915097.

Solution 2:

if you really need to do it via ssh, this is working with docker 1.8.2

init docker:

eval "$(docker-machine env default)"

get the IP from your default docker machine:

docker-machine ip default

this prints something like this out: 192.168.99.100

ssh [email protected]

password is tcuser but you can also use the identity file, see other answer

Solution 3:

Finally, I found an answer :

I'm on Windows with Docker Toolbox (Docker Machine).

If I docker-machine -D ssh default, I find that the SSH parameters should be :

Host : localhost
Port : 51701
User : docker
Key : .docker\machine\machines\default\id_rsa

When I change my Putty/MobaXterm settings to match, voila, I can SSH into the container.

Solution 4:

For the hackers out there, here is a script that will ssh into the 'active' docker-machine. This also gives you the values for the ssh_key, ssh_port, and the ssh_user, making it possible to do things like rsync between the localhost and the VM.

#!/bin/bash
docker_machine_name=$(docker-machine active)
docker_ssh_user=$(docker-machine inspect $docker_machine_name --format={{.Driver.SSHUser}})
docker_ssh_key=$(docker-machine inspect $docker_machine_name --format={{.Driver.SSHKeyPath}})
docker_ssh_port=$(docker-machine inspect $docker_machine_name --format={{.Driver.SSHPort}})

ssh -i $docker_ssh_key -p $docker_ssh_port $docker_ssh_user@localhost

You can copy and paste that into your terminal, line for line, and it will work. Or, make the script into a function, and feed it the name as an argument.