→ 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
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
Port mapping allows us to forward traffic from the host machine to the container, enabling external access.
Let's set up an Apache Web Server inside a Docker container and expose it to the internet.