2019独角兽企业重金招聘Python工程师标准>>>
1. 拉取镜像
docker pull mysql:5.7
2. 查看当前所有的镜像
docker image ls
3. 创建并启动一个容器
docker run --name test-mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql:5.7
-name
: 给新创建的容器命名,此处命名为test-mysql
-e
: 配置信息,此处配置 mysql 的 root 用户的登录密码-p
: 端口映射,此处映射主机的3306端口到容器test-mysql
的3306端口- -d: 成功启动同期后输出容器的完整ID
- 最后一个
mysql:5.7
指的是mysql
镜像
4. 查看容器运行状态
docker ps
5. 进入容器
docker exec -it test-mysql /bin/bash
6. 连接 mysql
- 可以通过工具直接连接服务器的3306端口
- 也可以进入容器,然后通过
mysql -u root -p
连接
7. 可以启动多个 mysql 容器
docker run --name test2-mysql -e MYSQL_ROOT_PASSWORD=123456 -p 6666:3306 -d mysql
8. 查看所有容器
docker ps -a
9. 启动和关闭容器
docker start test-mysql # 指定容器名称
docker start 73f8811f669e # 指定容器ID
docker start test-mysql # 指定容器名称
docker start 73f8811f669e # 指定容器ID
10. 修改MySQL配置文件
-
方法一: 进入容器,然后修改容器里的配置文件 /etc/mysql/my.cnf
,重新启动容器。
-
方法二: 挂载主机的配置文件(官方文档)
The MySQL startup configuration is specified in the file /etc/mysql/my.cnf, and that file in turn includes any files found in the /etc/mysql/conf.d directory that end with .cnf. Settings in files in this directory will augment and/or override settings in /etc/mysql/my.cnf. If you want to use a customized MySQL configuration, you can create your alternative configuration file in a directory on the host machine and then mount that directory location as /etc/mysql/conf.d inside the mysql container.
If /my/custom/config-file.cnf is the path and name of your custom configuration file, you can start your mysql container like this (note that only the directory path of the custom config file is used in this command):
docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
This will start a new container some-mysql where the MySQL instance uses the combined startup settings from /etc/mysql/my.cnf and /etc/mysql/conf.d/config-file.cnf, with settings from the latter taking precedence.
转载于:https://my.oschina.net/shadowolf/blog/3048918
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)