天天看点

docker安装mysql后占用资源_【Docker】安装MySQL彻底解决3306端口占用问题

1.问题闪现:

[email protected]:~/Work/Learning/Docker/docker_compose$ docker-compose up -d

myshop_tomcat is up-to-date

Starting myshop_mysql ...

myshop_redis is up-to-date

Starting myshop_mysql ... error

ERROR: for myshop_mysql Cannot start service mysql: driver failed programming external connectivity on endpoint myshop_mysql (c42794af6a45ae1f176660abcd493c6c6345ddaec5c30ac84761e75cd3848484): Error starting userland proxy: listen tcp 0.0.0.0:3306: bind: address already in use

ERROR: for mysql Cannot start service mysql: driver failed programming external connectivity on endpoint myshop_mysql (c42794af6a45ae1f176660abcd493c6c6345ddaec5c30ac84761e75cd3848484): Error starting userland proxy: listen tcp 0.0.0.0:3306: bind: address already in use

ERROR: Encountered errors while bringing up the project.

2.尝试解决手段:

[email protected]:~/Work/Learning/Docker/docker_compose$ netstat -apn | grep 3306

(并非所有进程都能被检测到,所有非本用户的进程信息将不会显示,如果想看到所有信息,则必须切换到 root 用户)

tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -

[email protected]:~/Work/Learning/Docker/docker_compose$ sudo netstat -apn | grep 3306

[sudo] yunduo 的密码:

tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 9727/mysqld

[email protected]:~/Work/Learning/Docker/docker_compose$ sudo netstat -apn | grep 3306

tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 9727/mysqld

y[email protected]:~/Work/Learning/Docker/docker_compose$ kill -9 9727

bash: kill: (9727) - 不允许的操作

[email protected]:~/Work/Learning/Docker/docker_compose$ sudo netstat -apn | grep 3306

tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 9727/mysqld

yunduo@YunDuo:~/Work/Learning/Docker/docker_compose$ sudo kill -9 9727

[email protected]:~/Work/Learning/Docker/docker_compose$ sudo netstat -apn | grep 3306

tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 6623/mysqld

[email protected]:~/Work/Learning/Docker/docker_compose$ sudo netstat -apn | grep 6623

tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 6623/mysqld

unix 2 [ ACC ] 流 LISTENING 15031431 6623/mysqld /var/run/mysqld/mysqld.sock

mysqld杀不死!!!

2.彻底解决手段:

一旦运行MySQL镜像,MySQL 服务器自启动,ubuntu下彻底停止mysql:sudo /etc/init.d/mysql stop

#ubuntu下彻底停止mysql

[email protected]:~/Work/Learning/Docker/docker_compose$ sudo /etc/init.d/mysql stop

[ ok ] Stopping mysql (via systemctl): mysql.service.

#查看3306端口是否还在占用

[email protected]:~/Work/Learning/Docker/docker_compose$ sudo netstat -apn | grep 3306

[email protected]:~/Work/Learning/Docker/docker_compose$ docker-compose up -d

myshop_redis is up-to-date

Starting myshop_mysql ...

Starting myshop_mysql ... done

[email protected]:~/Work/Learning/Docker/docker_compose$ docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

32673b9daaad mysql:5.7 "docker-entrypoint.s…" 15 minutes ago Up 13 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp myshop_mysql

04f40a67818a tomcat:7 "catalina.sh run" 19 minutes ago Up 19 minutes 0.0.0.0:8080->8080/tcp myshop_tomcat

56b8e65d078c redis:5.0.2 "docker-entrypoint.s…" 19 minutes ago Up 19 minutes 0.0.0.0:6379->6379/tcp myshop_redis