Docker Machine #Tip : SSH into the Docker Machine

With the release of the Docker Toolbox, the recommended practice now is to use the docker-machine utility to set the environment for the Docker Machine that you want to target. Then you can use the docker client to run commands against the machine.

This is well and good. But if you prefer that you are inside the shell of the Docker Machine, you could directly ssh into it and run your commands there. The docker-machine client has a ssh command that you could use as follows:

docker-machine ssh <machine-name>

Let us take an example. On my machine, I have the following 3 Docker machines setup:

docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
default virtualbox Running tcp://192.168.99.100:2376
dev virtualbox Running tcp://192.168.99.101:2376
machine007 virtualbox Running tcp://192.168.99.102:2376

Now, instead of using the docker-machine env command, I want to directly SSH into say the dev machine.  Just do the following:

docker-machine ssh dev
 ## .
 ## ## ## ==
 ## ## ## ## ## ===
 /"""""""""""""""""\___/ ===
 ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
 \______ o __/
 \ \ __/
 \____\_______/
 _ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.8.1, build master : 7f12e95 - Thu Aug 13 03:24:56 UTC 2015
Docker version 1.8.1, build d12ea79
docker@dev:~$ 

Now go ahead and run your docker <command> directly from the shell prompt. You can type exit anytime to return back to your environment.

Advertisements

3 thoughts on “Docker Machine #Tip : SSH into the Docker Machine

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s