Video in progress
What do the two port numbers in docker run -p 8080:8080 mean?
The left one is the port on the host machine, the right one is the port inside the container. A request that arrives at the host's 8080 is forwarded to 8080 inside the container.
📖 Answer
A container lives in its own network environment, and its ports are not visible from outside. -p HOST:CONTAINER connects the two.
# the app listens on 8080 inside, we reach it from outside via 9000
docker run -p 9000:8080 shop-api:0.1
curl http://localhost:9000/actuator/health
If you need two instances of one app on the same machine, the internal port stays the same and the external port differs: -p 9001:8080 and -p 9002:8080.
A common mistake: Spring Boot runs with server.port=8081, but you used -p 8080:8080. The container starts, but requests come back with "connection reset", because nobody is listening on 8080 inside. Just look at the "Tomcat started on port" line in docker logs.
Sign up to mark studied questions and save your progress.