5000). To reach that app from outside the Docker host you must map a host port to the container port.
Two IP addresses to consider:
- The container IP: Every container receives an internal IP assigned by Docker (for example,
172.17.0.2). This IP is reachable only from the Docker host or other containers on the same Docker network. If you open a browser on the Docker host, you can usehttp://<container-ip>:5000to reach the app. - The Docker host IP: To make the app accessible from other machines, publish a container port to a host port. That exposes the application on the host IP and chosen host port (for example,
http://<docker-host-ip>:80).
-p option with the format -p <hostPort>:<containerPort>:
80 to container port 5000. Requests sent to http://<docker-host-ip>:80 will be forwarded to port 5000 inside the container.
Common scenarios and examples:
-p usage
If a host port is already taken by another container or process, Docker will not start the new container. Choose a free host port or stop the conflicting service before mapping.
Remember: container IPs are internal to Docker networks. To make a container accessible externally, publish a container port to a free host port using
-p hostPort:containerPort.- Docker run reference — Networking options
- Docker networking documentation
- Docker cheat sheet — Common commands