为什么我无法连接到Nginx Docker服务?

j9per5c4  于 2023-03-29  发布在  Nginx
关注(0)|答案(1)|浏览(205)

我试图在Docker Swarm中创建Nginx服务,但无法连接到它。

docker swarm init
docker service create -p 80:80 nginx:1.23.3

结果:

$ docker service ls
ID             NAME          MODE         REPLICAS   IMAGE          PORTS
8ka52nhkbkl2   epic_euclid   replicated   1/1        nginx:1.23.3   *:80->80/tcp

$ docker container ls
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS     NAMES
78dd33736e04   nginx:1.23.3   "/docker-entrypoint.…"   53 seconds ago   Up 51 seconds   80/tcp    epic_euclid.1.9b1c5cansiemzi3zoiom85zkg

如果我使用没有服务的容器,它工作正常:

docker run --rm -p 80:80 nginx:1.23.3

我还尝试创建新的映像和EXPOSE 80端口,但没有成功:

FROM nginx:1.23.3
EXPOSE 80

我在Windows和Linux上都试过这样做,结果是一样的。

$ docker version
Client: Docker Engine - Community
 Cloud integration: v1.0.31
 Version:           20.10.23
 API version:       1.41
 Go version:        go1.18.10
 Git commit:        7155243
 Built:             Thu Jan 19 17:34:13 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop
 Engine:
  Version:          20.10.23
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.10
  Git commit:       6051f14
  Built:            Thu Jan 19 17:32:04 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.18
  GitCommit:        2456e983eb9e37e47538f59ea18f2043c9a73640
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
igsr9ssn

igsr9ssn1#

我重新启动了Swarm,它解决了这个问题:

docker swarm init --default-addr-pool 192.168.100.0/24 --default-addr-pool-mask-length 26 --data-path-port=7789

来源:https://forums.docker.com/t/docker-swarm-service-unreachable-from-manager-node/133755/16

相关问题