1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #11954 from ankushagarwal/#11953

Use different host and container port for clarity
This commit is contained in:
James Turnbull 2015-04-01 09:21:15 -04:00
commit a73b7354a6
2 changed files with 8 additions and 7 deletions

View file

@ -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.
@ -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
@ -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

View file

@ -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