docker 运行mysql出错:The container name “/mysql“ is already in use by container

[root@iZwz97but8tjijoed local]# docker run -p 3306:3306 --name mysql \
> -v /usr/local/docker/mysql/logs:/var/log/mysql \
> -v /usr/local/docker/mysql/data:/var/lib/mysql \
> -v /usr/local/docker/mysql/conf/my.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf \
> -e MYSQL_ROOT_PASSWORD=123456 \
> -d mysql:5.7

参数说明:

-p 3306:3306:将容器的3306端口映射到主机的3306端口
-v /usr/local/docker/mysql/logs:/var/log/mysql:将日志文件夹挂载到主机
-v /usr/local/docker/mysql/data:/var/lib/mysql:将配置文件夹挂载到主机
-e MYSQL_ROOT_PASSWORD=123456:初始化root用户的密码

执行运行命令后,报错了,它说有同名的实例在运行

docker: Error response from daemon: Conflict. The container name "/mysql" is already in use by container "f154e3d09563e7cc23307bd513ffc56dd3f78bc825908df95a4c59c043030bc1". You have to remove (or rename) that container to be able to reuse that name.

那就看看正在运行的实例有哪些:

[root@iZwz97bu0gr8jijoed local]# docker ps -a
CONTAINER ID   IMAGE         COMMAND                  CREATED       STATUS                   PORTS                                                  NAMES
f154e3d09563   mysql:5.7     "docker-entrypoint.s…"   2 hours ago   Up 2 hours               0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
aaa672c11140   redis         "docker-entrypoint.s…"   2 hours ago   Exited (0) 2 hours ago                                                          redis
96c3bb2fb776   mysql         "docker-entrypoint.s…"   4 days ago    Exited (0) 2 hours ago                                                          mysql8.0
f209c67409c2   hello-world   "/hello"                 5 days ago    Exited (0) 5 days ago                                                           inspiring_jennings
[root@iu0gr8vwt8th6su3Z local]# docker rm f154e3d09563

移除正在运行的那个实例:又报错了

[root@iZwz97bu0grjijoed local]# docker rm f154e3d09563
Error response from daemon: You cannot remove a running container f154e3d09563e7cc23307bd513ffc56dd3f78bc825908df95a4c59c043030bc1. Stop the container before attempting removal or force remove

原因:不能删除一个正在运行中的容器,要先停止下来才能删除

[root@iZwz97bu0gr8tjijoed local]# docker stop f154e3d09563e7cc23307bd513ffc56dd3f78bc825908df95a4c59c043030bc1
f154e3d09563e7cc23307bd513ffc56dd3f78bc825908df95a4c59c043030bc1

现在再移除:

[root@iZwz97fdag8vwt8tjijoed local]# docker rm f154e3d09563
f154e3d09563

成功啦,现在执行运行命令就没问题了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杨幂等

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值