1 00:00:00,001 --> 00:00:01,901 [No Audio] 2 00:00:01,901 --> 00:00:05,334 In this demo, we will map our host machine's port 3 00:00:05,334 --> 00:00:09,267 to container port. The command is fairly simple, 4 00:00:09,267 --> 00:00:13,234 as we just have to extend the run command with a flag. 5 00:00:13,901 --> 00:00:19,301 We will map our hosts port 8080 to container's port 80 6 00:00:19,301 --> 00:00:23,867 on tcp by mentioning it following -p. 7 00:00:24,267 --> 00:00:27,101 Notice that the image we used here is 8 00:00:27,101 --> 00:00:31,434 the one that we had created while working with expose instruction. 9 00:00:32,433 --> 00:00:34,467 Now when we run the containers, 10 00:00:34,467 --> 00:00:37,367 we will get the ports mentioned in the output. 11 00:00:38,001 --> 00:00:40,767 The output looks a bit messy, but the 12 00:00:40,767 --> 00:00:42,667 annotations should help here. 13 00:00:43,101 --> 00:00:47,334 Now, we'll create another container from the same image called cont 14 00:00:47,334 --> 00:00:49,934 cont_nginx-A 15 00:00:50,734 --> 00:00:52,667 Instead of providing ports and 16 00:00:52,667 --> 00:00:55,601 protocols like earlier, this time, we will just 17 00:00:55,601 --> 00:01:00,134 provide capital -P and allow Docker to map 18 00:01:00,134 --> 00:01:04,700 ports by itself. Here, it will use the information 19 00:01:04,700 --> 00:01:08,034 provided by expose instruction in the Dockerfile 20 00:01:08,134 --> 00:01:12,301 and Tally available ports from host machines network drivers. 21 00:01:12,534 --> 00:01:16,367 We can see that the new container port 80 22 00:01:16,367 --> 00:01:23,267 mapped from container to port 32768 of host. 23 00:01:23,667 --> 00:01:25,734 We can also view this information 24 00:01:25,734 --> 00:01:30,434 by hitting docker container port command followed by the container name. 25 00:01:30,667 --> 00:01:32,967 Finally, when we run local 26 00:01:32,967 --> 00:01:37,334 host on port 8080 on our web browser, we can see 27 00:01:37,334 --> 00:01:42,201 nginx homepage which indicates that our port mapping was successful. 28 00:01:42,801 --> 00:01:46,067 When we do the same with the other container, 29 00:01:46,701 --> 00:01:48,667 it shows the same thing as well. 30 00:01:49,034 --> 00:01:52,334 In next lecture, we'll clean up our workspace.