Selected topic
Networking
Prefer practical output? Use related tools below while reading.
In Docker, port mapping allows you to expose a port from a running container to the host machine's network stack. This enables communication between the container and external services or applications.
bash
docker run -p 8080:80 mywebserver:latest-p 8080:80 maps the host machine's port 8080 (on the left) to the container's port 80 (on the right). This is called a "port mapping" or "expose port".mywebserver:latest specifies the Docker image name and tag.mywebserver:latest).http://localhost:8080 on your host machine, Docker will forward requests to the container running on port 80, allowing you to interact with the web server inside the container.
bash
docker run -p <host_port>:<container_port> <image_name>
Here:<host_port> is the host machine's port.<container_port> is the container's port (inside the container).<image_name> is the Docker image name and tag.bash
docker run -p 8080:80 -p 443:443 mywebserver:latest
This maps both port 8080 to port 80 and port 443 to port 443 inside the container.