← Docker learning path
Docker · Module 4 of 10

Ports and networking

Containers have their own network; you publish ports so others can reach them.

📖 Key ideas

  1. A container listens on its own ports, invisible to the outside by default.
  2. -p 8080:80 maps host port 8080 to container port 80.
  3. Containers on the same user-defined network reach each other by name.
  4. docker network create appnet makes a network; --network appnet joins it.
  5. 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