February 2019
Intermediate to advanced
240 pages
5h 25m
English
As we know, containers are isolated sandboxes. How is it that we’re able to reach our app by visiting http://localhost:3000 on our local machine?
The truth is, containers wouldn’t be very useful if there was no way of reaching them from outside of Docker. The whole point of a web server, for example, is that it’s accessible to people making requests.
Although, by default, a container can only be accessed from within the Docker network it’s connected to (more on this in How Containers Can Talk to Each Other), we can make it accessible externally by publishing one or more ports with docker run’s -p option.
In our command, we specified -p 3000:3000; this publishes the container’s port 3000 (the second number) ...