可以通过curl访问docker服务,但不能从postman / chrome访问

编程入门 行业动态 更新时间:2024-10-25 14:34:42
本文介绍了可以通过curl访问docker服务,但不能从postman / chrome访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I'm doing the docker getting started guide: docs.docker/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 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 localhost:80 (it loads forever). Why and how can I fix it?

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

I can access my service in the browser from: 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访问

本文发布于:2023-10-29 04:09:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538681.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以通过   curl   docker   postman   chrome

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!