1.问题闪现:###
初次up mysql报3306端口被占用
yunduo@YunDuo:~/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 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.尝试解决手段:###
杀死占用对应端口进程
yunduo@YunDuo:~/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
#kill3306端口占用的进程
yunduo@YunDuo:~/Work/Learning/Docker/docker_compose$ sudo kill -9 9727
#再次查询发现3306端口还是被占用
yunduo@YunDuo:~/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
mysqld杀不死!!!
2.彻底解决手段:###
一旦运行MySQL镜像,MySQL 服务器自启动,ubuntu下彻底停止mysql:sudo /etc/init.d/mysql stop
#ubuntu下彻底停止mysql
yunduo@YunDuo:~/Work/Learning/Docker/docker_compose$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
#查看3306端口是否还在占用
yunduo@YunDuo:~/Work/Learning/Docker/docker_compose$ sudo netstat -apn | grep 3306
yunduo@YunDuo:~/Work/Learning/Docker/docker_compose$ docker-compose up -d
myshop_redis is up-to-date
Starting myshop_mysql ...
Starting myshop_mysql ... done
yunduo@YunDuo:~/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