天天看點

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