[No Audio]
In this demo, we will map our host machine's port
to container port. The command is fairly simple,
as we just have to extend the run command with a flag.
We will map our hosts port 8080 to container's port 80
on tcp by mentioning it following -p.
Notice that the image we used here is
the one that we had created while working with expose instruction.
Now when we run the containers,
we will get the ports mentioned in the output.
The output looks a bit messy, but the
annotations should help here.
Now, we'll create another container from the same image called cont
cont_nginx-A
Instead of providing ports and
protocols like earlier, this time, we will just
provide capital -P and allow Docker to map
ports by itself. Here, it will use the information
provided by expose instruction in the Dockerfile
and Tally available ports from host machines network drivers.
We can see that the new container port 80
mapped from container to port 32768 of host.
We can also view this information
by hitting docker container port command followed by the container name.
Finally, when we run local
host on port 8080 on our web browser, we can see
nginx homepage which indicates that our port mapping was successful.
When we do the same with the other container,
it shows the same thing as well.
In next lecture, we'll clean up our workspace.