Docker Community Forums

Share and learn in the Docker community.

Possible issue in the documentation regarding Port Binding


(Nagarajan) #1

Hi,

I have been reading and trying out stuff from the amazing documentation, but came across this small issue which I wanted to notify about, so it can help people who read it in the future.

The QuickStart section has the following snippet which helps to understand how we can bind ports to a docker container and try and access the same from the host. I am using a Mac and I had trouble seeing the last step work - the hello world message never pops up when I try to fetch the logs. Reading some other part of the documentation I came across this docker-machine ip default, option to find the IPAddress and replaced 127.0.0.1 with the same in the echo command and then it worked as expected.

Bind a service on a TCP port

Bind port 4444 of this container, and tell netcat to listen on it

$ JOB=$(docker run -d -p 4444 ubuntu:12.10 /bin/nc -l 4444)

Which public port is NATed to my container?

$ PORT=$(docker port $JOB 4444 | awk -F: ‘{ print $2 }’)

Connect to the public port

$ echo hello world | nc 127.0.0.1 $PORT

Verify that the network connection worked

$ echo “Daemon received: $(docker logs $JOB)”

Also the command docker run gives an error with ubuntu:12.10 but works with ubuntu:latest

$ JOB=$(docker run -d -p 4444 ubuntu:12.10 /bin/nc -l 4444)
docker: Error response from daemon: Container command ‘/bin/nc’ not found or does not exist…

Fix:

Changed ubuntu:12.10 to ubuntu for the /nc issue

and for the host port issue

Added this step and modified the echo by adding a $HOST

Whats the ip address of the docker machine?

HOST=$(docker-machine ip default)

Connect to the public host/port

echo hello world | nc $HOST $PORT

May be the documentation needs a fix in general or atleast for Mac users.

Thanks,
-Naga