在宿主機(jī)的 /mnt/src/docker-containers/wyrover-mysql/mysql-data
創(chuàng)建目錄
在 wyrover-mysql 目錄下創(chuàng)建 start-server.sh
docker run --name wyrover-mysql -v /mnt/src/docker-containers/wyrover-mysql/mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password -d mysql:latest
啟動(dòng)后可在 mysql-data
目錄下看到相關(guān)的數(shù)據(jù)庫文件
然后在啟一個(gè) docker 容器連一下, 在 wyrover-mysql 目錄下創(chuàng)建 start-client.sh
docker run -it --link wyrover-mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
在宿主 bash 下運(yùn)行
./start-client.sh
就登錄到了 mysql叁熔,然后查看數(shù)據(jù)庫
show databases;
整個(gè)過程
docker@default:/mnt/src/docker-containers/wyrover-mysql$ ./start-client.sh
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> exit;
Bye
docker@default:/mnt/src/docker-containers/wyrover-mysql$