我在两台 Linux 机器上运行这个命令:
docker run -d --name registry --restart=always -p 4000:5000 -v registry:/var/lib/registry registry:2
一一,端口按预期发布:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0cae195defe8 registry:2 "/entrypoint.sh /etc…" 3 seconds ago Up 2 seconds 0.0.0.0:4000->5000/tcp registry
$ ss -nltp|grep 4000
LISTEN 0 4096 0.0.0.0:4000 0.0.0.0:*
另一方面,它没有:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5d3726252a61 registry:2 "/entrypoint.sh /etc…" 4 seconds ago Up 3 seconds registry
$ ss -nltp|grep 4000
$
什么可能导致 docker 不在第二台机器上发布该端口?
注意:重新启动机器并不能解决问题。
编辑端口发布不起作用的机器的 Docker 版本:
Client: Docker Engine - Community
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:03:17 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.17
API version: 1.41 (minimum version 1.12)
Go version: go1.17.11
Git commit: a89b842
Built: Mon Jun 6 23:01:23 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.6
GitCommit: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
runc:
Version: 1.1.2
GitCommit: v1.1.2-0-ga916309
docker-init:
Version: 0.19.0
GitCommit: de40ad0
它所工作的机器的 docker 版本完全相同,只是客户端多了一行:
Cloud integration 0.1.18