# docker pull mysql:5.7
# docker inspect mysql:5.7
##
"Entrypoint": [ "docker-entrypoint.sh" ],
##掛載到容器內/docker-entrypoint-initdb.d;MySQL啓動時將執行 01_create_database.sqlmysql
# pwd # /root/mysql-5.7/init-data # ls # 01_create_database.sql ##content create database test_database DEFAULT CHARSET utf8 COLLATE utf8_general_ci; grant all privileges on `test_database`.* to 'test_user'@'%' identified by '123456'; flush privileges;
##掛載到容器內 /var/lib/mysqlsql
# cd /root/mysql-5.7 # mkdir mysql # cd mysql # pwd # /root/mysql-5.7/mysql
# docker run -p 33336:3306 \
-v /root/mysql-5.7/mysql:/var/lib/mysql \
-v /root/mysql-5.7/init-data:/docker-entrypoint-initdb.d \
-e MYSQL_ROOT_PASSWORD=123456 \
--name mysql_5.7 \
-d mysql/mysql:5.7
# docker exec -ti <containerID> sh # mysql -uroot -p123456 # show databases;
參考:docker