2017-10-18 50 views
1

我做的是搬运工入门指南: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 -4 http://localhost

<h3>Hello World!</h3><b>Hostname:</b> 1532cae6e06f<br/>.... 

但是,要http://localhost:80(它加载永远)我无法从Chrome或邮递员访问它。为什么以及如何修复它?


更新19/10/17:

我可以访问我的服务在浏览器中:http://192.168.1.68:80。 这是领导节点的地址(这是我的真机的IP也..)。

但为什么我不能做到这一点从本地主机也?

+0

你运行邮递员为卷曲? – frennky

+0

是.............. –

回答

0

我在原生应用程序的Ubuntu上遇到同样的问题,当邮递员控制台说错误是连接被拒绝,并且出于某种原因将请求的地址转换为本地主机,这将不起作用。

0

尝试使用bridge network。桥网将与主机共享资源网络。例如,如果你在网络conatiner与港口80:80设置,您可以用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: bridge