问题描述
我更改了一些 mysql 配置设置并设置了错误,现在 Docker 容器不断重启,我在主机文件系统中找不到要编辑的 my.cnf
文件.我已经尝试过 aufs/diff 文件夹,但到目前为止找不到它.也试过了:
I changed some mysql config settings and set something wrong, now Docker container keeps restarting and I cannot find the my.cnf
file to edit in host filesystem. I have tried aufs/diff folders but so far unable to find it. Also tried:
find / -name my.cnf -exec nano {} ;
但它不会显示我更改的文件.我尝试将 config.v2.json
更改为启动 /bin/bash
而不是 mysqld
并重新启动 docker,但它却启动了 mysqld
(due supervisor or something?) 使用官方 mysql 容器镜像.
But it does not bring up the file I changed. And I tried to change config.v2.json
to start /bin/bash
instead of mysqld
and restarted docker, but yet it started mysqld
(due supervisor or something?) using official mysql container image.
推荐答案
我看到了两种可能的解决方案:
I am seeing two possible solutions for your problem:
绕过 MySQL 映像的入口点
通过运行 docker images
找到你的镜像名称,然后运行:
Find your image name by running docker images
then run:
docker run -it --entrypoint="/bin/sh" OPTIONS image
这应该带你到容器内的 bash,然后你可以从那里执行所有你想找到 my.cnf
文件的命令.虽然我不知道是否从那里编辑文件,但保存它并尝试再次运行它会起作用.我没试过.
That should take you to the bash inside the container and from there you can execute all the commands you want to find your my.cnf
file. Although I don't know if editing the file from there, save it and try to run it again will works. I didn't tried.
删除旧图并使用正确的方式编辑my.cnf
文件
Delete the old image and use the proper way to edit the my.cnf
file
运行 docker images
找到你的镜像名称,然后运行 docker rmi
Find your image name by running: docker images
and then delete it by running docker rmi <image_name>
在 MySQL Dockerhub 上查看默认 MySQL 映像的文档非常直接我引用:
Check the docs for the default MySQL images at MySQL Dockerhub is pretty straight on this and I quote:
使用自定义 MySQL 配置文件 MySQL 启动
Using a custom MySQL configuration file The MySQL startup
配置在文件/etc/mysql/my.cnf 中指定,并且文件依次包括在/etc/mysql/conf.d 中找到的任何文件以 .cnf 结尾的目录.此目录中的文件中的设置将增加和/或覆盖/etc/mysql/my.cnf 中的设置.如果你想使用自定义的 MySQL 配置,您可以创建自己的替代方案主机目录中的配置文件,然后挂载该目录位置为 mysql 内的/etc/mysql/conf.d容器.
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.
如果/my/custom/config-file.cnf 是您自定义的路径和名称配置文件,你可以像这样启动你的mysql容器(注意在此仅使用自定义配置文件的目录路径命令):
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 -eMYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
这将开始一个新的MySQL 实例使用组合的容器 some-mysql来自/etc/mysql/my.cnf 的启动设置和/etc/mysql/conf.d/config-file.cnf,来自后者的设置优先.
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.
从那时起,如果您在主机上创建 my.cnf
文件,那么您将永远不会再遇到此问题,因为您可以根据需要多次编辑该文件.
From that point and if you create the my.cnf
file on your host then you'll never run into this problem again since you can edit the file as many times as you want.
这篇关于/etc/mysql/my.cnf 更改后 MySQL 容器崩溃,如何编辑回来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!