docker swarm - 无法连接到nginx容器

时间:2018-03-31 21:54:58

标签: docker docker-swarm

我在单个节点上设置了Docker swarm,并在其上创建了一个运行nginx服务器的容器,但是我无法连接到指定端口上的nginx服务器。此外,我无法附加到容器。非常感谢任何帮助。

[user@hostname yum.repos.d]$ sudo docker swarm init
[user@hostname yum.repos.d]$ sudo docker info | grep -i "swarm: active"
Swarm: active
[user@hostname yum.repos.d]$
[user@hostname yum.repos.d]$ sudo docker node ls
ID                           HOSTNAME                      STATUS  AVAILABILITY  MANAGER STATUS
xxxxxxxxxxxxxxx *            hostname.server.com           Ready   Active        Leader
[user@hostname yum.repos.d]$ sudo docker service create --name web --publish 8080:80 nginx
[user@hostname ~]$ sudo docker ps -a
[sudo] password for user: 
CONTAINER ID        IMAGE                                                                           COMMAND                  CREATED             STATUS              PORTS               NAMES
xxxxxxxxxxx        nginx@sha256:ccdb5fdf47709493f9fc5af32478c0d86b3cbee0c306e3f04a0d3e640a50ea2d   "nginx -g 'daemon ..."   About an hour ago   Up About an hour    80/tcp              web.1.
[user@hostname ~]$ elinks http://localhost:8080 //says request sent but  no response received.

以上elinks命令无法连接到网址。

1 个答案:

答案 0 :(得分:0)

它有效!!

[user@hostname ~]$ sudo docker service ps web
ID                  NAME                IMAGE               NODE                           DESIRED STATE       CURRENT STATE           ERROR               PORTS
xxxxxxxxxxxx        web.1               httpd:latest        hostname.myserver.com   Running             Running 3 minutes ago                       
[user@hostname ~]$ 
[user@hostname ~]$ elinks http://hostname.mylabserver.com:80

这适用于连接到在端口80上运行的nginx。

谢谢!