1.启动docker
- 查看docker的运行状态 systemctl status docker
- 启动docker systemctl start docker
- 停止docker systemctl stop docker
2.启动mysql
- 查看所有docker镜像 docker ps -a
- 查看运行中的docker进行 docker ps -s
docker ps 其它操作:
docker ps [OPTIONS] 其他参数-a :显示所有的容器,包括未运行的。-f :根据条件过滤显示的内容。–format :指定返回值的模板文件。-l :显示最近创建的容器。-n :列出最近创建的n个容器。–no-trunc :不截断输出。-q :静默模式,只显示容器编号。-s :显示总的文件大小。
- 启动mysql docker run mysql(或者容器id)
- 本地登录mysql
- docker exec -it mysql /bin/bash
- mysql -u root -p 按要求输入密码即可登录 ``` root@ef8b19faba40:/# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.53 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> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
Database changed mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘root’ WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from user; +———+———+ | user | host | +———+———+ | root | % | +———+———+
<a name="E3fFm"></a>#### docker exec命令简介docker exec :在运行的容器中执行命令
docker exec [OPTIONS] CONTAINER COMMAND [ARG…]
OPTIONS说明:
-d :分离模式: 在后台运行
-i :即使没有附加也保持STDIN 打开
-t :分配一个伪终端 ```
