What if you could instantly open any app inside a container right on your own computer without hunting for IPs?
Why Exposing ports to host in Docker? - Purpose & Use Cases
Imagine you run a web app inside a container, but you want to see it in your browser on your computer. Without connecting the container's port to your computer, you can't access the app easily.
Manually trying to find the container's IP and open ports is confusing and slow. You might guess wrong or forget to open the right ports, causing errors and frustration.
Exposing ports to the host means telling Docker to link a container's port to your computer's port. This makes your app reachable just like any other program on your machine.
docker run myapp
# Then try to find container IP and port manuallydocker run -p 8080:80 myapp # Now access app at localhost:8080
This lets you easily test and use container apps from your own computer without extra hassle.
Running a website inside a container and opening it in your browser at http://localhost:8080 to see your changes live.
Manual port access is confusing and error-prone.
Exposing ports links container apps to your computer ports.
This makes testing and using container apps simple and fast.