Browse code

Use different host and container port for clarity

Fixes #11953

Signed-off-by: Ankush Agarwal <ankushagarwal11@gmail.com>

Ankush Agarwal authored on 2015/03/31 19:03:18
Showing 2 changed files
... ...
@@ -35,9 +35,10 @@ range* on your Docker host. Next, when `docker ps` was run, you saw that port
35 35
     bc533791f3f5  training/webapp:latest  python app.py 5 seconds ago  Up 2 seconds  0.0.0.0:49155->5000/tcp  nostalgic_morse
36 36
 
37 37
 You also saw how you can bind a container's ports to a specific port using
38
-the `-p` flag:
38
+the `-p` flag. Here port 80 of the host is mapped to port 5000 of the 
39
+container:
39 40
 
40
-    $ docker run -d -p 5000:5000 training/webapp python app.py
41
+    $ docker run -d -p 80:5000 training/webapp python app.py
41 42
 
42 43
 And you saw why this isn't such a great idea because it constrains you to
43 44
 only one container on that specific port.
... ...
@@ -47,9 +48,9 @@ default the `-p` flag will bind the specified port to all interfaces on
47 47
 the host machine. But you can also specify a binding to a specific
48 48
 interface, for example only to the `localhost`.
49 49
 
50
-    $ docker run -d -p 127.0.0.1:5000:5000 training/webapp python app.py
50
+    $ docker run -d -p 127.0.0.1:80:5000 training/webapp python app.py
51 51
 
52
-This would bind port 5000 inside the container to port 5000 on the
52
+This would bind port 5000 inside the container to port 80 on the
53 53
 `localhost` or `127.0.0.1` interface on the host machine.
54 54
 
55 55
 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
59 59
 
60 60
 You can also bind UDP ports by adding a trailing `/udp`. For example:
61 61
 
62
-    $ docker run -d -p 127.0.0.1:5000:5000/udp training/webapp python app.py
62
+    $ docker run -d -p 127.0.0.1:80:5000/udp training/webapp python app.py
63 63
 
64 64
 You also learned about the useful `docker port` shortcut which showed us the
65 65
 current port bindings. This is also useful for showing you specific port
... ...
@@ -160,9 +160,9 @@ to a high port (from *ephemeral port range* which typically ranges from 32768
160 160
 to 61000) on the local Docker host. We can also bind Docker containers to
161 161
 specific ports using the `-p` flag, for example:
162 162
 
163
-    $ docker run -d -p 5000:5000 training/webapp python app.py
163
+    $ docker run -d -p 80:5000 training/webapp python app.py
164 164
 
165
-This would map port 5000 inside our container to port 5000 on our local
165
+This would map port 5000 inside our container to port 80 on our local
166 166
 host. You might be asking about now: why wouldn't we just want to always
167 167
 use 1:1 port mappings in Docker containers rather than mapping to high
168 168
 ports? Well 1:1 mappings have the constraint of only being able to map