原创

Docker删除容器之后端口还是被占用

参考:

1.停止所有的容器

docker stop $(docker ps -q)

2.强制移除此容器

docker rm -f mysql1

3.清理此容器的网络占用

格式:docker network disconnect --force 网络模式 容器名称

示例:docker network disconnect --force bridge mysql1

4.简查是否还有同名容器占用

格式:docker network inspect 网络模式

示例:docker network inspect bridge

示范

[root@docker ~]# docker run -e ES_JAVA_POTS="Xms=256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 --name ES01 5acf0e8da90b
bf7e2577fab37a375d2a3d008e39010f47fdb0c3ecf72530c07751b30ce2d055
/usr/bin/docker-current: Error response from daemon: service endpoint with name ES01 already exists.
[root@docker ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                           PORTS                                                                                        NAMES
bf7e2577fab3        5acf0e8da90b        "/docker-entrypoin..."   59 seconds ago      Created                                                                                                                       ES01
5ff7a918f705        d69a5113ceae        "docker-entrypoint..."   4 hours ago         Exited (255) About an hour ago   4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp   rabbitmq
51dc4b255a3d        f336949ce7a1        "/docker-entrypoin..."   3 days ago          Exited (255) About an hour ago                                                                                                zk01
[root@docker ~]# docker rm -f bf7e2577fab3
bf7e2577fab3
[root@docker ~]# docker network disconnect --force nat ES01
Error response from daemon: network nat not found
[root@docker ~]# docker network disconnect --force bridge ES01
[root@docker ~]# docker network inspect ES01
[]
Error: No such network: ES01
[root@docker ~]# docker run -e ES_JAVA_POTS="Xms=256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 --name ES01 5acf0e8da90b
68daeda250af2b72ad4a828f4812bb79cd9f4517ee032070e8e5ffd5be0c9e36
[root@docker ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                            NAMES
68daeda250af        5acf0e8da90b        "/docker-entrypoin..."   16 seconds ago      Up 14 seconds       0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   ES01
[root@docker ~]#

docker ps之后发现,容器已经可以正常运行。

↓↓↓ 打开微信关注我的微信公众号 ↓↓↓

会打篮球的程序猿

领取精品免费学习资料哦~
正文到此结束
本文目录