可以从curl访问docker服务,但不能从postman / chrome访问
我正在执行docker入门指南: https : //docs.docker.com/get-started/part3/#recap-and-cheat-sheet-optional
泊坞窗,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或邮递员访问它。 为什么以及如何解决?
17/10/17更新:
我可以从http://192.168.1.68:80
的浏览器访问我的服务。 这是领导者节点的地址(也是我的真机的ip也是..)。
但为什么我不能从本地做呢?
我在Ubuntu上有这个原生应用程序的相同问题,当邮递员控制台说错误是连接被拒绝,并出于某种原因将请求的地址转换为本地主机,这将无法正常工作…
尝试使用bridge network
。 桥网将与主机共享资源networking。 例如,如果您使用端口80:80
在web conatiner中设置,则可以使用localhost:80
进行访问。 所以在docker-compose文件中添加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: bridge