Docker-Error after running Mysql container: [ERROR] --initialize specified but the data directory has files in it. Aborting.

created at 10-18-2021 views: 80

background

Run and start the mysql container on the local mac docker

docker run -d -p 3306:3306 --name mysql1 -v /Users/polo/data/conf:/etc/mysql/conf.d -v /Users/polo/data/mysql:/var/lib/mysql  -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

Phenomenon

Check the container log and find that an error is reported, and the local Navicat cannot be connected

[ERROR] --initialize specified but the data directory has files in it. 
[ERROR] Aborting. 

cause

The directory mounted by -v already has files, so when -v selects a local directory, remember to select an empty directory/non-existent directory (it will be created automatically)

solution

Replace the local directory mounted by -v with an empty directory/non-existent directory

created at:10-18-2021
edited at: 10-18-2021: