可以通过curl访问docker服务,但不能从postman / chrome访问 [英] Can access docker service from curl but not from postman/chrome

查看:624
本文介绍了可以通过curl访问docker服务,但不能从postman / chrome访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做docker入门指南: https://docs.docker.com/get-started/part3/#recap-and-cheat-sheet-optional

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:

我通过运行 docker stack deploy -c docker-compose.yml getstartedlab 部署了我的应用程序。
然后从curl上访问我的服务,它可以正常工作 curl -4 http:// localhost

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/>....

但是我无法从Chrome或邮递员访问它通过转到 http:// localhost:80 (它将永远加载)。为什么以及如何解决它?

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?

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

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..).

但是为什么我不能

推荐答案

看到 curl -4 ... 使我怀疑这是ipv6问题。如果未为ipv6配置本地计算机,并且localhost在hosts文件中引用了ipv6地址,则对localhost的调用将挂起。

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.

很简单,在您的网址中转到 127.0.0.1 而不是 localhost

The workaround is rather simple, go to 127.0.0.1 instead of localhost in your urls.

这篇关于可以通过curl访问docker服务,但不能从postman / chrome访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆