1. 下載mysql image
# docker pull mysql:8
2. 查看目前的images 有哪些
# docker images
3. 啟動 mysql,把容器的3306 port 對應到本機的 3306 port ,初始化密碼為 Lab3306
# docker run --name labdb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=Lab3306 -d mysql:8
4. 查看容器執行狀態
# docker ps -a
5. 進入mysql 的容器中
# docker exec -it labdb bash
6. 跳出容器,但不關閉容器
ctrl-p + q
7. docker start 再次回到容器的 shell 中,後面可以接 CONTAINER ID 或是 NAMES
# docker start bb0ab4e9b251
或是
# docker start labdb
如果是要透過本機連線的話,先安裝mysql client
# apt install -y default-mysql-client
# mysql -h 127.0.0.1 -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.31 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test2 |
+--------------------+
5 rows in set (0.002 sec)
MySQL [(none)]>
留言列表