我正在做码头入门指南: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:我通过运行docker stack deploy -c docker-compose.yml getstartedlab来部署我的应用程序。然后从curl访问我的服务,这是一个工作良好的curl -4 http://localhost。
<h3>Hello World!</h3><b>Hostname:</b> 1532cae6e06f<br/>....但是我不能通过访问http://localhost:80 (它永远加载)从chrome或postman访问它。我怎么才能修好它?
更新19/10/17:
我可以在浏览器中从:http://192.168.1.68:80访问我的服务。它是领导节点的地址(这也是我的真正机器的ip )。
,但为什么我也不能从本地主机做呢?
发布于 2018-05-07 22:55:12
看到curl -4 ...让我怀疑这是一个ipv6问题。如果您的本地机器没有为ipv6配置,而且localhost对主机文件中的ipv6地址有一个引用,那么对localhost的调用将挂起。
解决方法相当简单,在您的urls中使用127.0.0.1而不是localhost。
发布于 2017-12-15 03:48:22
尝试使用bridge network。桥接网络将与主机共享资源网络。例如,如果您在带有端口80:80的web管理员中设置,则可以使用localhost:80进行访问。因此,将driver: bridge添加到您的坞-撰写文件中,如下所示
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: bridgehttps://stackoverflow.com/questions/46814642
复制相似问题