→ Docker allows us to run applications in isolated environments called containers. By default, containers are only accessible from within the host machine. However, using port mapping, we can make a Docker container accessible from the internet.

This guide explains:

✔️ How to map host and container ports

✔️ Running services like Apache and Jenkins inside Docker

✔️ Differences between docker expose, docker publish (-p), docker exec, and docker attach

✔️ Practical step-by-step examples


🔹 Understanding Docker Port Mapping

By default, a Docker container is isolated, meaning:

❌ You cannot access the container from the internet.

❌ You cannot directly reach services running inside a container.

👉 Solution: Port Mapping

docker-engine-port-publishing-2000-opt.png

Understanding Docker Port Mapping to Bind Container Ports.jpg

Port mapping allows us to forward traffic from the host machine to the container, enabling external access.


🔹 Exposing a Web Server Running in Docker

Let's set up an Apache Web Server inside a Docker container and expose it to the internet.