继续使用:堆栈服务器无休止地加载页面

Eth*_*gue 7 docker docker-compose

我一直在密切关注docker入门指南 - 除了我的python应用程序中的一些更改,我已经确认这些更改没有问题,我已经推送到Docker hub.

但是,当我到达第3部分并尝试加载时localhost:80,页面只是无休止地加载.

我的命令:

$ docker swarm init
Swarm initiated: ...
$ docker stack deploy -c docker-compose.yml
Creating network getstartedlab_webnet
Creating service getstartedlab_web
$ docker stack ps getstartedlab
ID                  NAME                  IMAGE                     NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
fhxqr2u8hxar        getstartedlab_web.1   mctague/friendlyhello:2   cube                Running             Running 29 seconds ago                       
4t9mu9r8147e        getstartedlab_web.2   mctague/friendlyhello:2   cube                Running             Running 28 seconds ago                       
duute2pvgu9z        getstartedlab_web.3   mctague/friendlyhello:2   cube                Running             Running 30 seconds ago                       
9kav6v27qfjn        getstartedlab_web.4   mctague/friendlyhello:2   cube                Running             Running 29 seconds ago                       
1s2imbiuk6e2        getstartedlab_web.5   mctague/friendlyhello:2   cube                Running             Running 29 seconds ago                       
$ docker logs <one of the running containers>
 * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
$ curl localhost:80
< either an endless loading that I have to cancel with ^C,
  *OR* Connection refused >
Run Code Online (Sandbox Code Playgroud)

泊坞窗,compose.yml

version: "3"
services:
  web:
    image: mctague/friendlyhello:2
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "80:80"
    networks:
      - webnet
networks:
  webnet:
Run Code Online (Sandbox Code Playgroud)

Ale*_*rov 6

在某些系统中,curl默认为localhost连接到ip6.所以你可以运行curl:

$ curl 127.0.0.1:80
Run Code Online (Sandbox Code Playgroud)

要么

$ curl -4 localhost:80
Run Code Online (Sandbox Code Playgroud)


小智 5

Alexey 的回答也是我的问题。我通过向/etc/sysctl.conf添加以下两行(在 CentOS 7 上)解决了禁用 ipv6(因此默认为 ipv4)的问题:

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
Run Code Online (Sandbox Code Playgroud)

然后执行sysctl -p(全部以 root/su 身份)。