paul
paul

Reputation: 13471

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.

Upvotes: 2

Views: 414

Answers (3)

Wolfgang Fahl
Wolfgang Fahl

Reputation: 15594

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/

Upvotes: 2

Adam B
Adam B

Reputation: 1774

Are you trying to connect to a running container or trying to connect to the virtualbox image running the docker daemon?

If the first, you cannot just SSH into a running container unless that container is running an ssh daemon. The easiest way to get a shell into a running container is with docker exec -ti <container name/id> /bin/sh. Do a docker ps to see running containers.

If the second, if your host was created with docker-machine then you can ssh into it with docker-machine ssh <machine name>. You can see all of you're running machines with docker-machine ls.

If this doesn't help can you clarify your question a little and provide details around how your creating your image and starting the container.

Upvotes: 2

John Jones
John Jones

Reputation: 33

You can use ssh keys to access passwordless.

Here's some intro https://wiki.archlinux.org/index.php/SSH_keys

Upvotes: -1

Related Questions