Docker:编辑"my.cnf"停止容器中的文件 [英] Docker: Edit "my.cnf" file in stopped container

查看:190
本文介绍了Docker:编辑"my.cnf"停止容器中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对"my.cnf"进行编辑后,当我尝试启动容器时,我现在在Mac上从Kitematic收到一个错误:

After making an edit to "my.cnf", I now get an error from Kitematic on the Mac when I attempt to start the container:

mysqld: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at line 19! mysqld: 
        [ERROR] Fatal error in defaults handling. Program aborted!

我尝试通过以下方式访问容器:

I've tried accessing the container via:

docker exec -it [container] bash

...但是我得到了错误:

... but I get the error:

Error response from daemon: Container [container] is not running

我能够通过图像访问某物,但是文件看起来并不相同,所以我不确定发生了什么(我不太熟悉Docker. ).

I was able to access something via the image, but the file didn't appear to be the same, so I'm not sure what was happening (I'm not too conversant with Docker).

在此阶段,进行适当的编辑并修复容器,或者以某种方式将MySQL数据克隆到另一个容器将是理想的选择.

At this stage, either making the appropriate edit and fixing the container, or somehow cloning the MySQL data to another container would be ideal.

推荐答案

要修复my.cnf,可以使用docker container cp.它适用于停止的容器. 试试

To fix the my.cnf, you can use docker container cp. It works with stopped containers. Try

docker container cp [container]:/etc/mysql/my.cnf container-my.cnf

然后编辑container-my.cnf并复制回去:

then edit container-my.cnf and copy back:

docker container cp container-my.cnf [container]:/etc/mysql/my.cnf


要在新容器中使用现有的MySQL数据,


To use the existing MySQL data with a new container:

docker container inspect -f '{{.Mounts}}' [container]

为您提供数据所在的卷名(键volume).然后启动一个新的mysql容器并将卷安装在/var/lib/mysql下:

gives you the volume name (key volume) where the data is. Then start a new mysql container and mount the volume under /var/lib/mysql:

docker container run -d -v [volume_name]:/var/lib/mysql [image]

此后,您可以删除旧容器(实际上,您可以在创建新容器之前将其删除)

Afterwards you can remove the old container (Actually you can remove it before creating the new one)

这篇关于Docker:编辑"my.cnf"停止容器中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆