我有2个容器正在使用服务器的端口5001和5000运行。该服务器可以是Docker集群的一部分。当我使用Docker swarm leave --force
离开docker群时,我的物理端口的重定向已消失。
[98-swarm-hello-world *]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dfc9bbc8573b registry "/entrypoint.sh /etc…" 7 seconds ago Up 5 seconds 0.0.0.0:5001->5000/tcp docker-registry_registry-private_1
760cbf6e6b15 registry "/entrypoint.sh /etc…" 7 seconds ago Up 5 seconds 0.0.0.0:5000->5000/tcp docker-registry_registry-mirror_1
[98-swarm-hello-world *]$ docker swarm init
Swarm initialized: current node (srlmoh6a2nm28biifgv7vpjb1) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-1hws6so0lpikgc1e0ztlhpobj7ejvg0hg4lk0k22wsdss4ntri-7l6eoo7cimlhmpzputbjpo6qt 192.168.65.3:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
[98-swarm-hello-world *]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dfc9bbc8573b registry "/entrypoint.sh /etc…" 21 seconds ago Up 19 seconds 0.0.0.0:5001->5000/tcp docker-registry_registry-private_1
760cbf6e6b15 registry "/entrypoint.sh /etc…" 21 seconds ago Up 19 seconds 0.0.0.0:5000->5000/tcp docker-registry_registry-mirror_1
目前端口仍然在这里,但随后是:
[98-swarm-hello-world *]$ docker swarm leave --force
Node left the swarm.
[98-swarm-hello-world *]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dfc9bbc8573b registry "/entrypoint.sh /etc…" 33 seconds ago Up 31 seconds docker-registry_registry-private_1
760cbf6e6b15 registry "/entrypoint.sh /etc…" 33 seconds ago Up 31 seconds docker-registry_registry-mirror_1
编辑:我的图片可能有问题,另一张图片(使用docker container run --rm --name nginx -p 80:80 -d nginx
创建),端口仍然暴露:
[root@n0300 docker-registry]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f40e2463eb38 registry "/entrypoint.sh /etc…" 6 seconds ago Up 2 seconds 0.0.0.0:5001->5000/tcp docker-registry_registry-private_1
fbb31476bddf registry "/entrypoint.sh /etc…" 6 seconds ago Up 2 seconds 0.0.0.0:5000->5000/tcp docker-registry_registry-mirror_1
b3086042d2f5 nginx "nginx -g 'daemon of…" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp nginx
[root@n0300 docker-registry]# docker swarm init
Swarm initialized: current node (s5fpahqg1klnbi2w90pver5ao) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-3b2gv5e1f3x4ez9s3itf5hxnilypvh0g4t4butdhggwqpjsx2n-c4l1o42p4fl9mwy8ktjhl3yzo 172.16.1.44:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
[root@n0300 docker-registry]# docker swarm leave --fore
unknown flag: --fore
See 'docker swarm leave --help'.
[root@n0300 docker-registry]# docker swarm leave --force
Node left the swarm.
[root@n0300 docker-registry]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f40e2463eb38 registry "/entrypoint.sh /etc…" 22 seconds ago Up 18 seconds docker-registry_registry-private_1
fbb31476bddf registry "/entrypoint.sh /etc…" 22 seconds ago Up 18 seconds docker-registry_registry-mirror_1
b3086042d2f5 nginx "nginx -g 'daemon of…" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp nginx
编辑2:我的映像没有建立,我只是在运行一个容器。
这是compose file
:
version: '3'
services:
registry-mirror:
image: registry
environment:
- REGISTRY_HTTP_ADDR=0.0.0.0:5000
volumes:
- ./config-mirror-registry.yml:/etc/docker/registry/config.yml
ports:
- "5000:5000"
registry-private:
image: registry
environment:
- REGISTRY_HTTP_ADDR=0.0.0.0:5000
ports:
- "5001:5000"
这里是config file
version: 0.1
log:
fields:
service: registry
storage:
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /var/lib/registry
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled: true
interval: 10s
threshold: 3
proxy:
remoteurl: https://registry-1.docker.io