docker 使用 MySql
docker 安装 MySql
- 通过命令拉取 MySql 镜像 docker pull mysql
- 运行 MySql 容器 docker run -itd -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --name mysql-test mysql
命令说明:运行 MySQL,给定别名 mysql-test,容器内端口 3306 映射到主机端口 3306,设置 root 用户密码为 123456 - 查询正在运行的容器 docker ps
- 查询所有容器 docker ps -a
- 查询本地镜像 docker images
- 启动/关闭/重启容器 docker start/stop/restart [CONTAINER ID/NAMES]
docker 进入 MySQL 容器内部
-
命令:docker exec -it mysql-test bash
命令说明:在容器名为 mysql-test 中运行 bash 脚本C:\Users\Administrator>docker exec -it mysql bash root@8c29b4fc61c7:/# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.22 MySQL Community Server - GPL Copyright (c) 2000, 2020, 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>