SSH into Docker Toolbox
orphan
SSH into Docker Toolbox
Requirements
You shell must have an SSH client (the ssh command or equivalent).
* howto-open-terminal-on-mac * howto-open-terminal-on-win *
howto-find-docker-toolbox-ip-address
Manual
Before going to use the automated approach, you should understand how to
fetch all required information via the docker-machine command.
Gather all information
-
Get active Toolbox machine name
Terminal window host> docker-machine activedefault -
Print all information
Terminal window host> docker-machine -D ssh defaultHost : localhostPort : 51701User : dockerKey : .docker\machine\machines\default\id_rsa
Gather specific information
-
Get active Toolbox machine name
Terminal window host> docker-machine activedefault -
Get SSH username (Using machine name
defaultfrom above)Terminal window host> docker-machine inspect default --format={{.Driver.SSHUser}}docker -
Get SSH public key (Using machine name
defaultfrom above)Terminal window host> docker-machine inspect default --format={{.Driver.SSHKeyPath}}.docker\machine\machines\default\id_rsa -
Get local SSH port (Using machine name
defaultfrom above)Terminal window host> docker-machine inspect default --format={{.Driver.SSHPort}}51701 -
Get Docker Toolbox IP address (Using machine name
defaultfrom above)Terminal window host> docker-machine ip default192.168.99.100
SSH into Docker Toolbox
Now with the above gathered information you can ssh into Docker Toolbox in two different ways:
-
via local port-forwarded ssh port (automatically forwarded by Docker Toolbox)
Terminal window -
via Docker Toolbox IP address
Terminal window
Automated
Instead of typing all of the above manually each time, you can also create a small bash script to automate this.
-
Create a file
ssh-docker.shand add the following to it:#!/bin/bashdocker_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 -
Run it:
Terminal window host> bash ssh-docker.sh
stackoverflow ssh into docker machine