docker pull mysql
docker pull mysql:5.7.38 这个mysql:5.7.38代表的时候拉取mysql5.7.38这个版本的数据库
具体可以在dockerhub上寻找你想要的版本https://hub.docker.com/_/mysql?tab=tags
docker images # 输出 zhangjianwei@zhangjianweideMacBook-Pro ~ % docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql latest 64e1d555ec03 6 days ago 482MB
docker run -p 3307:3306 --name mysql -v /Users/zhangjianwei/docker/mysql/mysql1/conf:/etc/mysql/conf.d -v /Users/zhangjianwei/docker/mysql/mysql1/logs:/logs -v /Users/zhangjianwei/docker/mysql/mysql1/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql
docker ps # 输出 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6324587475fd mysql "docker-entrypoint.s…" 11 minutes ago Up 11 minutes 33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp mysql
docker exec -it mysql /bin/bash
mysql -u root -p123456