How to ssh into docker-machine VirtualBox instance?

后端 未结 7 1956
萌比男神i
萌比男神i 2020-12-22 16:57

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 th

相关标签:
7条回答
  • 2020-12-22 17:55

    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.

    0 讨论(0)
提交回复
热议问题