Reputation: 22456
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.
Upvotes: 89
Views: 80088
Reputation: 1
you can use use the ordinary synatx used on your terminal login :docker && pasword:tcuser
exemple : ssh [email protected] pw:tcuser
Upvotes: 0
Reputation: 308
We can also ssh into the docker via following command -
docker exec -it /bin/sh
Upvotes: -1
Reputation: 7679
For mac OX,the machine and its keys are located here (make sure you have the keys in there, something like the below:
~/project/dev/docker_notes za$ ls /Users/za/.docker/machine/machines/default/
.DS_Store ca.pem config.json disk.vmdk id_rsa.pub server-key.pem
boot2docker.iso cert.pem default/ id_rsa key.pem server.pem
1) list available vms.
> ~/project/dev/docker_notes za$ docker-machine ls
> NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
> default - virtualbox Running tcp://192.168.99.100:2376 v1.11.0
In my case, the name of the machine is default. So, just
~/project/dev/docker_notes za$ docker-machine ssh default
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
_ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.11.0, build HEAD : 32ee7e9 - Wed Apr 13 20:06:49 UTC 2016
Docker version 1.11.0, build 4dc5990
docker@default:~$ vi
.ash_history .ashrc .docker/ .local/ .profile .ssh/ log.log
docker@default:~$ ls
log.log
As you can see, I am able to ssh into docker-machine/instance.
docker@default:~$ uname -a
Linux default 4.1.19-boot2docker #1 SMP Thu Apr 7 02:41:05 UTC 2016 x86_64 GNU/Linux
You can also follow this > howto - docker
Upvotes: 2
Reputation: 46500
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.
Upvotes: 129
Reputation: 1532
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.
Upvotes: 12
Reputation: 5241
If for some reason you'd rather use the ssh
command rather than docker-machine ssh
, you can do
ssh `docker-machine ip machine_name` -ldocker -i ~/.docker/machine/machines/machine_name/id_rsa
Upvotes: 5
Reputation: 16602
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
Upvotes: 73
Reputation: 251
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.
Upvotes: 25