I'm doing the docker getting started guide: https://docs.docker.com/get-started/part3/#recap-and-cheat-sheet-optional
docker-compose.yml:
version: "3"
services:
web:
# replace username/repo:tag with your name and image details
image: username/repo:tag
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "80:80"
networks:
- webnet
networks:
webnet:
I deployed my app by running docker stack deploy -c docker-compose.yml getstartedlab
.
Then Accessing my service from curl which working fine curl -4 http://localhost
<h3>Hello World!</h3><b>Hostname:</b> 1532cae6e06f<br/>....
But I can't access it from chrome or postman by going to http://localhost:80
(it loads forever). Why and how can I fix it?
I can access my service in the browser from: http://192.168.1.68:80
.
It is the address of the leader node (which is the ip of my real machine also..).
But why can't I do it from localhost also?
Seeing the curl -4 ...
makes me suspect this is an ipv6 issue. If your local machine isn't configured for ipv6 and localhost has a reference to the ipv6 address in the hosts file, then calls to localhost will hang.
The workaround is rather simple, go to 127.0.0.1
instead of localhost
in your urls.
Try to use bridge network
. The bridge network will be share recource network with host. Example if you set in web conatiner with port 80:80
, you can access with localhost:80
.
so add driver: bridge
in your docker-compose file, like this
version: "3"
services:
web:
# replace username/repo:tag with your name and image details
image: username/repo:tag
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "80:80"
networks:
- webnet
networks:
webnet:
driver: bridge
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With