1.下载需要的版本
[root@docker ~]# docker search mysql [root@docker ~]# docker pull mysql:5.7
2.生成容器
[root@docker ~]# docker run -p 12345:3306 --name mysql -v ~/mysql/conf:/etc/mysql/conf.d -v /mysql/logs:/logs -v /mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWD=123456 -d mysql:5.7
3.查看容器
[root@docker mysql]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES0608c61406e8 mysql:5.7 "docker-entrypoint.sh" 13 seconds ago Up 10 seconds 33060/tcp, 0.0.0.0:12345->3306/tcp mysql
4.交互运行
[root@docker ~]# docker exec -it mysql /bin/bashroot@0608c61406e8:/# mysql -uroot -p123456
5.备份
[root@docker mysql]# docker exec mysql sh -c 'exec mysqldump --all-databases -uroot -p"123456" '> /mysql/all_databases.sqlmysqldump: [Warning] Using a password on the command line interface can be insecure.[root@docker mysql]# lsall_databases.sql conf data logs