Merge pull request #2512 from dudebout/correct-basics-doc

Corrects the TCP section of the basics use
This commit is contained in:
Andy Rothfusz 2013-11-01 13:55:28 -07:00
commit feef16bd88
1 changed files with 4 additions and 8 deletions

View File

@ -138,22 +138,19 @@ Listing all running containers
sudo docker ps sudo docker ps
Expose a service on a TCP port Bind a service on a TCP port
------------------------------ ------------------------------
.. code-block:: bash .. code-block:: bash
# Expose port 4444 of this container, and tell netcat to listen on it # Bind port 4444 of this container, and tell netcat to listen on it
JOB=$(sudo docker run -d -p 4444 ubuntu:12.10 /bin/nc -l 4444) JOB=$(sudo docker run -d -p 4444 ubuntu:12.10 /bin/nc -l 4444)
# Which public port is NATed to my container? # Which public port is NATed to my container?
PORT=$(sudo docker port $JOB 4444 | awk -F: '{ print $2 }') PORT=$(sudo docker port $JOB 4444 | awk -F: '{ print $2 }')
# Connect to the public port via the host's public address # Connect to the public port
# Please note that because of how routing works connecting to localhost or 127.0.0.1 $PORT will not work. echo hello world | nc 127.0.0.1 $PORT
# Replace *eth0* according to your local interface name.
IP=$(ip -o -4 addr list eth0 | perl -n -e 'if (m{inet\s([\d\.]+)\/\d+\s}xms) { print $1 }')
echo hello world | nc $IP $PORT
# Verify that the network connection worked # Verify that the network connection worked
echo "Daemon received: $(sudo docker logs $JOB)" echo "Daemon received: $(sudo docker logs $JOB)"
@ -183,4 +180,3 @@ You now have a image state from which you can create new instances.
Read more about :ref:`working_with_the_repository` or continue to the Read more about :ref:`working_with_the_repository` or continue to the
complete :ref:`cli` complete :ref:`cli`