docker-compose 部署 MySql

信息:

  • Docker版本($ docker --version):Docker版本18.03.1-ce,版本9ee9f40
  • 系统信息:Windows10专业版

mysql挂载在Docker的volume中

1.第一步:

docker volume create mysql-data

2.第二步:

创建一个mysql文件夹

3.第三步:

再mysql文件夹下创建docker-compose.yml

因最新版docker已不支持/g/的绝对路径表达方式,改为./的相对路径【以docker-compose.yml的相对路径】)

 version: ''
services:
db:
image: mysql/mysql-server
container_name: db-mysql
restart: always
command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci
ports:
- "3306:3306"
networks:
- net_db
environment:
MYSQL_ROOT_PASSWORD: pwd123456
volumes:
- mysql-data:/var/lib/mysql
volumes:
mysql-data:
external: true
networks:
net_db:
external: true

4.第四步:

docker-compose up

5.第五步:

登陆:   docker exec -it db-mysql bash mysql -uroot -p pwd123456

如果出现登陆不进,请重置:

Access denied for user 'root'@'localhost' (using password : YES)

请继续看:

删除镜像:

列出所有images: 
docker images
docker rmi   IMAGE ID

删除volume

  列出所有volume: 
docker volume ls docker volume rm mysql-data

删除mysql文件夹

重复上面的操作把第四步的命令加上db

 docker-compose up db
 C:\Users\GYW>docker exec -it db-mysql bash
bash-4.2# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 8.0. MySQL Community Server - GPL Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>

大功告成!!!

上一篇:利用MYSQL的函数实现用户登录功能,进出都是JSON(第一版)


下一篇:POJ2699_The Maximum Number of Strong Kings