简体   繁体   English

无法访问 Docker Swarm 中服务的 HTTP 端点

[英]Cannot access HTTP endpoint of a service in a Docker Swarm

I have an akka clustered application deployed to 3 nodes via Docker swarm.我有一个通过 Docker 群部署到 3 个节点的 akka 集群应用程序。 One of the node exposes an HTTP endpoint.其中一个节点公开了一个 HTTP 端点。 The problem now is that the HTTP endpoint cannot be accessed even though it looks as if the proper port mapping has been done.现在的问题是无法访问 HTTP 端点,即使它看起来好像已经完成了正确的端口映射。

Below is the output of running docker service ls下面是运行 docker service ls 的输出

docker service ls
ID                  NAME                    MODE                REPLICAS            IMAGE                                          PORTS
prbk5icazzw8        test_seed      replicated          1/1                 registry.me:5000/seedroute:0.1.0-SNAPSHOT      *:1600->1600/tcp, *:8000->8000/tcp
ldudkew6ym6q        test_worker1   replicated          1/1                 registry.me:5000/workerroute:0.1.0-SNAPSHOT    *:1601->1601/tcp
e2oonp28rrs3        test_worker2   replicated          1/1                 192.168.0.10:5000/workerroute:0.1.0-SNAPSHOT   *:1602->1602/tcp
pe1xzog9qw4y        registry                replicated          1/1                 registry:2                                     *:5000->5000/tcp

But when I login into the server running the test_seed node and do curl localhost:8000/members It seems the connection just hangs and I do not get a response in the return:但是当我登录到运行 test_seed 节点的服务器并执行curl localhost:8000/members时,连接似乎挂起并且我没有在返回中得到响应:

curl -v localhost:8000/members
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8000 (#0)
> GET /members HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.58.0
> Accept: */*
> 

using wget is the same, I get the following:使用 wget 是一样的,我得到以下信息:

wget localhost:8000/members
--2019-11-30 22:34:18--  http://localhost:8000/members
Resolving localhost (localhost)... ::1, 127.0.0.1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8000... connected.
HTTP request sent, awaiting response... 

Any idea what could be wrong?知道什么可能是错的吗? In summary, I have an HTTP server that is part of application deployed via Docker swarm, and I cannot access this HTTP server, even from the node it is running on.总之,我有一个 HTTP 服务器,它是通过 Docker swarm 部署的应用程序的一部分,我无法访问这个 HTTP 服务器,即使是从它运行的节点。

Any suggestions on how to fix this would be appreciated!任何有关如何解决此问题的建议将不胜感激!

Edit-1编辑-1

Forcing the request to use 1Pv4 also did not help:强制请求使用 1Pv4 也无济于事:

root@akka:~# curl -4 http://localhost:8000/members
curl: (7) Failed to connect to localhost port 8000: Connection refused

As you can see from the following line of your curl/wget output正如您从 curl/wget 输出的以下行中看到的

Resolving localhost (localhost)... ::1, 127.0.0.1, 127.0.0.1

your system is first resolving localhost to ::1 , the IPv6 lookback, which is not supported by Docker at the moment.您的系统首先将localhost解析为::1 ,即 IPv6 回溯,目前 Docker 不支持它。

Possible solutions are:可能的解决方案是:

  1. Use 127.0.0.1 : curl http://127.0.0.1:8000/members使用 127.0.0.1:curl curl http://127.0.0.1:8000/members
  2. Force IPv4 : curl -4 http://localhost:8000/members强制 IPv4curl -4 http://localhost:8000/members
  3. Disable IPv6 : As root, open /etc/sysctl.conf and add the following:禁用 IPv6 :以 root 身份打开/etc/sysctl.conf并添加以下内容:
     net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1
    Then run sysctl -p to apply the new settings.然后运行sysctl -p以应用新设置。

Bug's answer above helped, but curl was still hanging intermittently. Bug 上面的回答有所帮助,但 curl 仍然断断续续地挂起。 The following option below was least flaky with swarm.下面的以下选项对于 swarm 来说是最不稳定的。

Creating an overlay network docker network create -d overlay my-net and in the docker-compose.yml file marking this network external as follows:创建覆盖网络docker network create -d overlay my-net并在docker-compose.yml文件中将此网络标记为外部,如下所示:

networks:
  my-net:
    external: true

Services including traefik which used this my-net network were now accessible via curl.现在可以通过 curl 访问包括使用此my-net网络的traefik在内的服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM