How do I SSH into the boot2docker host vm that the Vagrant 1.6 Docker Provider sets up?

做~自己de王妃 提交于 2019-11-28 16:31:50
David256

Vagrant's boot2docker keeps boot2docker's ssh username and password.

SSH into VM

$ boot2docker ssh

Boot2Docker auto logs in using the generated SSH key, but if you want to SSH into the machine manually (or you're not using a boot2docker managed VM), the credentials are:

user: docker
pass: tcuser

https://github.com/boot2docker/boot2docker#ssh-into-vm

The port is forwarded from the local port 2022 by default. You can verify this:

$ VBoxManage list vms | grep docker
"docker-host_default_1234567890000_1234" {3d66ecf6-4539-47ca-afd2-66f953cd9a3e}
$ VBoxManage showvminfo docker-host_default_1234567890000_1234 | grep ssh
NIC 1 Rule(1):   name = ssh, protocol = tcp, host ip = 127.0.0.1, host port = 2022, guest ip = , guest port = 22

And then login:

$ ssh docker@localhost -p 2022
docker@localhost's password: tcuser
                        ##        .
                  ## ## ##       ==
               ## ## ## ##      ===
           /""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
           \______ o          __/
             \    \        __/
              \____\______/
 _                 _   ____     _            _
| |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
boot2docker: 0.8.0
docker@boot2docker:~$ 

Oct 2015: Boot2docker is deprecated in favor of docker-machine. To login:

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

$ docker-machine ssh default

You can ssh into docker host with vagrant ssh docker-host-id but first you need to know the docker-host-id.
You can get a list of all active Vagrant environments with vagrant global-status command.
To get the docker-host id you can filter with grep:

vagrant global-status | grep docker-host

you'll obtain an output similar to:

68f58d0  default  virtualbox running   /Users/yourUser/.vagrant.d/data/docker-host

copy the first column id, and then ssh into docker-host:

vagrant ssh 68f58d0

vagrant global status docs

You can also forgo using boot2docker's ssh function and do it "manually" like so:

$ ssh \
-i $HOME/.ssh/id_boot2docker \
-p $(boot2docker config 2>&1 | awk '/SSHPort/ {print $3}') \
docker@localhost

The arguments to -p is typically port 2022 but above shows how you can programmatically determine this if you want.

You can use SSH directly:

ssh docker@$(boot2docker ip)

(password: tcuser, see https://github.com/boot2docker/boot2docker#ssh-into-vm)


And you can also copy/paste your public key to the boot2docker machine, so you don't need to type the password every time:

cat ~/.ssh/id_rsa.pub | ssh docker@$(boot2docker ip) 'cat - >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys'

For vagrant host machines with vagrant password:

ssh -p 2222 vagrant@localhost

Otherwise with tcuser password:

ssh -p 2222 docker@localhost

Here is more information on why this works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!