boot2docker / boot2docker-cli

boot2docker management utility
Apache License 2.0
339 stars 95 forks source link

Clarification on Port Forwarding #101

Closed fearoffish closed 10 years ago

fearoffish commented 10 years ago

I'm having an issue getting to the ports in my containers.

I'm on Mac OS X, Mavericks. Using the 0.8.0 boot2docker-cli (408532a).

I've used a phusion/passenger-ruby21:0.9.9 image, with a docker file:

FROM phusion/passenger-ruby21:0.9.9

# Set correct environment variables.
ENV HOME /root

# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]

ADD docker/id_dsa.pub /tmp/your_key
RUN cat /tmp/your_key >> /root/.ssh/authorized_keys && rm -f /tmp/your_key
RUN chmod 0600 /root/.ssh/authorized_keys

EXPOSE 22

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

This works and I can connect from the docker VM using SSH. I see VirtualBox has the NAT network and the Host only network. So, here's my confusion as I can't SSH into the container from outside of the docker VM.

My IP: 172.20.10.2 The docker VM IPs: docker0: 172.17.42.1 eth0: 10.0.2.15 eth1: 192.168.59.103

The container IP: 172.17.0.2

If I traceroute to the container IP from my terminal, it goes out onto the Internet looking for it and fails. I'm no expert, but is my Airport IP messing this up in some way? It should go straight through the host only network to the container normally, right?

EDIT

VirtualBox says there is 1 host only network, and the adapter is 192.168.59.3, with the DHCP (192.168.59.99) serving 192.168.59.103...192.168.59.254. Should I have a DHCP client running and that's why it fails?

SvenDowideit commented 10 years ago

for starters, the boot2docker vm already has an ssh server on port 22 - so you won't be able to use it twice.

I think you'll have to post the actual commands you're using to start the container and then how and where from you're sshing. The IP addresses you mention above look very much right to me.

fearoffish commented 10 years ago

I start docker with:

docker run -t -i fearoffish/my-app /bin/bash

I run:

/sbin/my_init

I open another terminal window and run but the final command times out:

docker ps
docker inspect my-container | grep IP
ssh <the-ip>

If I do this I at least get a connection refused as my private key isn't in the boot2docker container:

docker ssh
ssh <the-ip>

So this is probably my own confusion, and the clarification is to fix that not boot2docker, sorry.

steeve commented 10 years ago

Have you tried running your container with the port 22 properly forwarded to the docker host (boot2docker vm) ?

fearoffish commented 10 years ago

Pardon my ignorance, but how do I do that?— Jamie

On Mon, May 12, 2014 at 2:18 PM, Steeve Morin notifications@github.com wrote:

Have you tried running your container with the port 22 properly forwarded to the docker host (boot2docker vm) ?

Reply to this email directly or view it on GitHub: https://github.com/boot2docker/boot2docker-cli/issues/101#issuecomment-42830256

steeve commented 10 years ago

docker inspect should tell you which port it did bind for the port 22.

Try to ssh on that port:

$ ssh -p <port> <ip>
fearoffish commented 10 years ago

I'm at ScotRuby right now, I'll try it out later, thanks.— Jamie

On Mon, May 12, 2014 at 7:49 PM, Steeve Morin notifications@github.com wrote:

docker inspect should tell you which port it did bind for the port 22. Try to ssh on that port:

$ ssh -p <port> <ip>

Reply to this email directly or view it on GitHub: https://github.com/boot2docker/boot2docker-cli/issues/101#issuecomment-42871999

SvenDowideit commented 10 years ago

@fearoffish

fearoffish commented 10 years ago

Sorry it took so long to get back to you on this, and I really appreciate the help.

docker inspect says there are no PortBindings for 22, 443 or 80. Do I need to set those manually?

SvenDowideit commented 10 years ago

yes, when you run a container, you need to tell docker that you want to make the ports to the host interfaces. By default, the container's EXPOSED ports are available for other containers to --link to only.

see the -p and -P options for docker run

SvenDowideit commented 10 years ago

closing, as this is a slow Docker @fearoffish swing by irc and it should be easy - unless its solved already :)