External Access Via Port Mappings
Let's learn how to map container ports to Docker host's ports.
Port mapping for container access
So far, we've said that containers on bridge networks can only communicate with other containers on the same network. However, you can get around this by mapping containers to ports on the Docker host. It's a bit clunky and has a lot of limitations, but it might be useful for occasional testing and development work.
The figure below shows a single Docker host running two containers. The web
container on the right is running a web server on port 80
that is mapped to port 5005
on the Docker host. The client
container on the left is sending requests to the Docker host on port 5005
and the external client at the bottom is doing the same. Both requests will hit the host’s IP on port 5005
and be redirected to the web server running in the web
container.
Get hands-on with 1400+ tech skills courses.