docker-compose 部署 MySql
信息:
- Docker版本(
$ docker --version
):Docker版本18.03.1-ce,版本9ee9f40 - 系统信息:Windows10专业版
mysql挂载在Docker的volume中
1.第一步:
1 docker volume create mysql-data
2.第二步:
创建一个mysql文件夹
3.第三步:
再mysql文件夹下创建docker-compose.yml
因最新版docker已不支持/g/的绝对路径表达方式,改为./的相对路径【以docker-compose.yml的相对路径】)
1 version: '3' 2 services: 3 db: 4 image: mysql/mysql-server 5 container_name: db-mysql 6 restart: always 7 command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci 8 ports: 9 - "3306:3306" 10 networks: 11 - net_db 12 environment: 13 MYSQL_ROOT_PASSWORD: pwd123456 14 volumes: 15 - mysql-data:/var/lib/mysql 16 volumes: 17 mysql-data: 18 external: true 19 networks: 20 net_db: 21 external: true
4.第四步:
docker-compose up
5.第五步:
登陆: 1 docker exec -it db-mysql bash 2 3 mysql -uroot -p 4 pwd123456
如果出现登陆不进,请重置:
Access denied for user 'root'@'localhost' (using password : YES)
请继续看:
删除镜像:
列出所有images:
docker images
docker rmi IMAGE ID
删除volume
1 列出所有volume:
2 docker volume ls
docker volume rm mysql-data
删除mysql文件夹
重复上面的操作把第四步的命令加上db
1 docker-compose up db
1 C:\Users\GYW>docker exec -it db-mysql bash 2 bash-4.2# mysql -uroot -p 3 Enter password: 4 Welcome to the MySQL monitor. Commands end with ; or \g. 5 Your MySQL connection id is 18 6 Server version: 8.0.11 MySQL Community Server - GPL 7 8 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 9 10 Oracle is a registered trademark of Oracle Corporation and/or its 11 affiliates. Other names may be trademarks of their respective 12 owners. 13 14 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 15 16 mysql>
大功告成!!!