我在使用官方MySQL docker镜像创建的docker容器中运行MySQL 5.7.20。 MySQL conf文件需要安装在主机Ubuntu系统上。
目前MySQL docker容器是使用该命令启动的
sudo docker run -d \ -p 3306:3306 \ -e MYSQL_ROOT_PASSWORD=test \ -v /root/test/mysql/var/lib:/var/lib/mysql \ -v /root/test/mysql/etc:/etc/mysql \ --name test-mysql \ mysql:5.7但是/root/test/mysql/etc中没有配置文件...连接到docker容器的bash,发现/etc/mysql是空的!
conf文件位于何处? 在/etc/mysql/conf.d/和/etc/mysql/mysql.conf.d/不应该有一些吗?
I am running MySQL 5.7.20 in a docker container created using the official MySQL docker image. The MySQL conf file needs to be mounted on the host Ubuntu system.
Currently the MySQL docker container is started using the command
sudo docker run -d \ -p 3306:3306 \ -e MYSQL_ROOT_PASSWORD=test \ -v /root/test/mysql/var/lib:/var/lib/mysql \ -v /root/test/mysql/etc:/etc/mysql \ --name test-mysql \ mysql:5.7However there are no conf files in /root/test/mysql/etc... Connected to the docker container's bash and found that /etc/mysql is empty!
Where are the conf files located? Shouldnt there be some in /etc/mysql/conf.d/ and /etc/mysql/mysql.conf.d/?
最满意答案
如果您在不安装任何卷的情况下运行该命令:
$ docker run -it mysql ls /etc/mysql conf.d my.cnf my.cnf.fallback mysql.cnf mysql.conf.d如果/root/test/mysql/etc作为空文件夹存在并将其挂载到/etc/mysql则/etc/mysql所有内容将被/root/test/mysql/etc “替换”。
您可以拥有一个空/root/test/mysql/etc文件夹并执行以下操作:
docker volume create --driver local \ --opt type=none \ --opt device=/root/test/mysql/etc \ --opt o=bind \ mysql_volsudo docker run -d \ -p 3306:3306 \ -e MYSQL_ROOT_PASSWORD=test \ -v /root/test/mysql/var/lib:/var/lib/mysql \ -v mysql_vol:/etc/mysql \ --name test-mysql \ mysql:5.7
If you run the command without mounting any volumes:
$ docker run -it mysql ls /etc/mysql conf.d my.cnf my.cnf.fallback mysql.cnf mysql.conf.dIf /root/test/mysql/etc exists as an empty folder and you mount it onto /etc/mysql all the content of /etc/mysql will be "replaced" with those in /root/test/mysql/etc.
You can have an empty /root/test/mysql/etc folder and do the following:
docker volume create --driver local \ --opt type=none \ --opt device=/root/test/mysql/etc \ --opt o=bind \ mysql_volsudo docker run -d \ -p 3306:3306 \ -e MYSQL_ROOT_PASSWORD=test \ -v /root/test/mysql/var/lib:/var/lib/mysql \ -v mysql_vol:/etc/mysql \ --name test-mysql \ mysql:5.7
更多推荐
发布评论