Search code examples
dockerboot2dockerdocker-compose

Connect docker container


I´ve been looking in google but i cannot find any answer.

It is possible connect to a virtualbox docker container that I just start up. I have the IP of the virtual machine, but if I try to connect by SSH of course ask me for a password.

Regards.


Solution

  • see https://github.com/BITPlan/docker-stackoverflowanswers/tree/master/33232371

    to repeat steps.

    On my Mac OS X machine

    docker-machine env default
    

    shows

     export DOCKER_HOST="tcp://192.168.99.100:2376"
    

    So i added an entry

    192.168.99.100 docker
    

    to my /etc/hosts

    so that ping docker works. As a Dockerfile i am using:

    # Ubuntu image
    FROM ubuntu:14.04
    

    which I am building with

    docker build -t bitplan/sshtest:0.0.1 . 
    

    and testing with

    docker run -it bitplan/sshtest:0.0.1 /bin/bash
    

    Now ssh docker will react with

    The authenticity of host 'docker (192.168.99.100)' can't be established.
    ECDSA key fingerprint is SHA256:osRuE6B8bCIGiL18uBBrtySH5+iGPkiHHiq5PZNfDmc.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added 'docker,192.168.99.100' (ECDSA) to the list of known hosts.
    wf@docker's password: 
    

    But here you are connecting to the docker machine not your image! The ssh port is at port 22. You need to redirect it to another port and configure your image to support ssh to root or a valid user.

    See e.g. https://docs.docker.com/examples/running_ssh_service/