mahonya
mahonya

Reputation: 10055

How to Ssh into docker container that is running inside Vagrant?

I am running a Vagrant VM under Windows 7 . The Vagrant VM is running a docker container. So the configuration is :

Windows7[Vagrant[Docker]]

I want to ssh from Windows into the Docker container.

The docker container is running sshd and I can successfully ssh from Vagrant VM to Docker container.

sudo docker ps

gives:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                   NAMES
64b13daab5f2        ubuntu:12.04        "/bin/bash"         14 minutes ago      Up 14 minutes       0.0.0.0:49153->22/tcp   thirsty_morse

From the Vagrant VM:

ssh root@localhost -p 49153

works just fine. So Vagrant VM's port 49153 is forwarded to Docker container's port 22.

I've added

config.vm.network "forwarded_port", guest:49153, host:49155

to Vagrantfile so that localhost:49155 on Windows is forwarded to Vagrant VM:49153

This is where things break down. When I try to ssh from Windows to localhost:49155, I get:

ssh: connect to host localhost port 49155: Connection refused

So Windows:49155 -> Vagrant:49153 is not working. I thought that it may be a problem related to listening on a port on Vagrant VM's external ip so I've installed rinetd into Vagrant VM and I've done:

bindadress    bindport  connectaddress  connectport
0.0.0.0       49153     127.0.0.1       49153

Still no luck. What am I missing here?

Upvotes: 2

Views: 2052

Answers (1)

mahonya
mahonya

Reputation: 10055

Ok, answering my own question. It works now. I think the most likely reason for the problem was that port 49153/55 and its neighbours is actually used by some windows services by default. I changed to mapping for ports in the Vagrant file to use 9090 for Windows and everything worked. No need to rinetd either. I've also done:

sudo docker run -v /vagrant:/opt/data -p 0.0.0.0:49153:22 -i -t ubuntu:12.04

Notice the 0.0.0.0: it may or may not be relevant but this configuration is working for me.

Upvotes: 1

Related Questions