← Docker learning pathDocker · Module 4 of 10
Ports and networking
Containers have their own network; you publish ports so others can reach them.
📖 Key ideas
- A container listens on its own ports, invisible to the outside by default.
- -p 8080:80 maps host port 8080 to container port 80.
- Containers on the same user-defined network reach each other by name.
- docker network create appnet makes a network; --network appnet joins it.
- EXPOSE in a Dockerfile documents a port but does not publish it.
💡 Real-life example: Like an apartment: the flat number is the container port, and the building gate (host port) is how visitors get in.
-p 8080:80Host port 8080 to container port 80
EXPOSEDocuments a listening port
Bridge networkDefault private network for containers
Container nameAddress other containers use on a user network