使用mysql镜像报错: Ports are not available
docker run -it --rm --name test_mysql -v mysql_data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 "mysql:8.0"
具体报错:
docker: Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:3306 -> 0.0.0.0:0: listen tcp 0.0.0.0:3306: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
time=“2024-07-14T11:00:44+08:00” level=error msg="error waiting for container: "
原因:
在同一时间,系统上已经有一个服务在监听端口3306。Docker无法在此端口上创建另一个服务,因为它需要唯一性,
解决:
更换端口映射:由3306:3306变为3307:3306
docker run -it --rm --name test_mysql -v mysql_data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3307:3306 "mysql:8.0"