標籤:always 檔案夾 ges 最新 command put pwd general exec
資訊:
- 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_db12 environment:13 MYSQL_ROOT_PASSWORD: pwd12345614 volumes: 15 - mysql-data:/var/lib/mysql16 volumes:17 mysql-data:18 external: true19 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 its11 affiliates. Other names may be trademarks of their respective12 owners.13 14 Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.15 16 mysql>
大功告成!!!
Docker 掛載Mysql用volume方式 docker-compose 登陸不進去