3.1 KiB
- orphan
SSH into Docker Toolbox
Table of Contents
- local
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
host> docker-machine active default
Print all information
host> docker-machine -D ssh default Host : localhost Port : 51701 User : docker Key : .docker\machine\machines\default\id_rsa
Gather specific information
Get active Toolbox machine name
host> docker-machine active default
Get SSH username (Using machine name
default
from above)host> docker-machine inspect default --format={{.Driver.SSHUser}} docker
Get SSH public key (Using machine name
default
from above)host> docker-machine inspect default --format={{.Driver.SSHKeyPath}} .docker\machine\machines\default\id_rsa
Get local SSH port (Using machine name
default
from above)host> docker-machine inspect default --format={{.Driver.SSHPort}} 51701
Get Docker Toolbox IP address (Using machine name
default
from above)host> docker-machine ip default 192.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)
host> ssh -i .docker\machine\machines\default\id_rsa -p 51701 docker@127.0.0.1
via Docker Toolbox IP address
host> ssh -i .docker\machine\machines\default\id_rsa docker@192.168.99.100
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.sh
and add the following to it:#!/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
Run it:
host> bash ssh-docker.sh