Container có network namespace riêng. Service bên trong có thể listen trên port 8000, nhưng host chỉ truy cập được nếu publish port hoặc cùng network có service khác gọi bằng container/service name.
Ví dụ:
docker run --rm -p 8080:8000 my-api8080:8000 nghĩa là host port 8080 trỏ vào container port 8000.
Trong Docker Compose, services cùng network thường gọi nhau bằng tên service, không gọi localhost.
A container has its own network namespace. A service inside it can listen on port 8000, but the host can only reach it when the port is published or another service on the same network calls it by container/service name.
Example:
docker run --rm -p 8080:8000 my-api8080:8000 means host port 8080 maps to container port 8000.
In Docker Compose, services on the same network usually call each other by service name, not localhost.