相关问题: docker mysql数据卷挂载?日志挂载?配置文件挂载?
1.配置文件挂载
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)。你需要把你预先定义的config-file.cnf放在主机/my/custom目录下
注意:这里笔者推荐,先启动一个不挂载数据卷的mysql,从该容器中把相关挂载文件docker cp到主机目录(当然你也可以到官网下载相应的文件)。因为当你挂载的主机目录为空时,docker会帮你创建一个对应的空目录,但相应的容器中的目录也会被置为空
# 5.8版本需要在后面设置密码加密方式已确保可远程连接
# --default-authentication-plugin=mysql_native_password
docker run -d -p 3306:3306 \
-v ${mysql-Contents}/conf:/etc/mysql/conf.d \
-v ${mysql-Contents}/data:/var/lib/mysql \
-v ${mysql-Contents}/logs:/var/log/mysql \
-e MYSQL_ROOT_PASSWORD=${root password} \
--name ${your container-name} ${image-name}:${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.
docker cp ${容器名}:/etc/mysql/conf.d/ ${mysql-Contents}/conf/
# 或
docker cp ${容器名}:/etc/mysql/my.cnf ${mysql-Contents}/conf/
2.日志挂载
docker cp ${容器名}:/var/log/mysql/error.log ${mysql-Contents}/logs/
3.数据挂载
1.Create a data directory on a suitable volume on your host system, e.g. /my/own/datadir.
2.Start your mysql container like this:
docker run --name some-mysql -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag