I creates a simple service with docker image. how I want to access it in localhost of my system.
docker service create --name my-app --replicas 3 -p 9090:8000 my-app-image
docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
ojvi1m6f8b41 my-app replicated 3/3 my-app-image:latest *:9090->8000/tcp
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92b7d0ee0732 my-app-image:latest "java -jar /app.jar" 39 seconds ago Up 33 seconds 9090/tcp my-app.2.corp0f0uln0ng4h9lrk6h09nl
4478d716939a my-app-image:latest "java -jar /app.jar" 39 seconds ago Up 33 seconds 9090/tcp my-app.1.v3wwxp1xz93sfonimg1uszaqz
52aab839c268 my-app-image:latest "java -jar /app.jar" 39 seconds ago Up 34 seconds 9090/tcp my-app.3.ihpy62i331h48b1mtuhr87z46
it seems service is running but I can not access it in http://localhost:8000
Please help
2
Answers
You’re mapping the port 9090 of the host, in this case your local computer, to the container port of 8000. In other words: You should be able to reach it locally on port 9090
For more information on container networking
you could access it in http://localhost:9090.
8000 is the port inside your docker container not accessible from outside.
The local port is 9090