Skip to content

Commit

Permalink
Use different host and container port for clarity
Browse files Browse the repository at this point in the history
Fixes moby#11953

Signed-off-by: Ankush Agarwal <[email protected]>
  • Loading branch information
ankushagarwal committed Mar 31, 2015
1 parent ddbc68f commit 8caf8f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions docs/sources/userguide/dockerlinks.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ range* on your Docker host. Next, when `docker ps` was run, you saw that port
bc533791f3f5 training/webapp:latest python app.py 5 seconds ago Up 2 seconds 0.0.0.0:49155->5000/tcp nostalgic_morse

You also saw how you can bind a container's ports to a specific port using
the `-p` flag:
the `-p` flag. Here port 80 of the host is mapped to port 5000 of the
container:

$ docker run -d -p 5000:5000 training/webapp python app.py
$ docker run -d -p 80:5000 training/webapp python app.py

And you saw why this isn't such a great idea because it constrains you to
only one container on that specific port.
Expand All @@ -47,9 +48,9 @@ default the `-p` flag will bind the specified port to all interfaces on
the host machine. But you can also specify a binding to a specific
interface, for example only to the `localhost`.

$ docker run -d -p 127.0.0.1:5000:5000 training/webapp python app.py
$ docker run -d -p 127.0.0.1:80:5000 training/webapp python app.py

This would bind port 5000 inside the container to port 5000 on the
This would bind port 5000 inside the container to port 80 on the
`localhost` or `127.0.0.1` interface on the host machine.

Or, to bind port 5000 of the container to a dynamic port but only on the
Expand All @@ -59,7 +60,7 @@ Or, to bind port 5000 of the container to a dynamic port but only on the

You can also bind UDP ports by adding a trailing `/udp`. For example:

$ docker run -d -p 127.0.0.1:5000:5000/udp training/webapp python app.py
$ docker run -d -p 127.0.0.1:80:5000/udp training/webapp python app.py

You also learned about the useful `docker port` shortcut which showed us the
current port bindings. This is also useful for showing you specific port
Expand Down
4 changes: 2 additions & 2 deletions docs/sources/userguide/usingdocker.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ to a high port (from *ephemeral port range* which typically ranges from 32768
to 61000) on the local Docker host. We can also bind Docker containers to
specific ports using the `-p` flag, for example:

$ docker run -d -p 5000:5000 training/webapp python app.py
$ docker run -d -p 80:5000 training/webapp python app.py

This would map port 5000 inside our container to port 5000 on our local
This would map port 5000 inside our container to port 80 on our local
host. You might be asking about now: why wouldn't we just want to always
use 1:1 port mappings in Docker containers rather than mapping to high
ports? Well 1:1 mappings have the constraint of only being able to map
Expand Down

0 comments on commit 8caf8f0

Please sign in to comment.