简体   繁体   English

docker容器中的打开文件已关闭

[英]Open file inside docker container has been shut down

I start a mysql container and change the config file inside a container, in this case is /etc/mysql/my.cnf . 我启动一个mysql容器并更改容器内的配置文件,在这种情况下为/etc/mysql/my.cnf And restart container. 并重新启动容器。

Maybe something wrong with that config file and the container cannot start. 该配置文件可能有问题,容器无法启动。 How can I edit that config file when the container has been shutdown? 容器关闭后如何编辑该配置文件?

A container is immutable, your changes and conf are gone. 容器是不可变的,您的更改和配置都消失了。 You should use a Dockerfile to build a custom image and include my.cnf. 您应该使用Dockerfile构建自定义映像并包含my.cnf。

It can be easily done, create a folder, create my.cnf in it and a Dockerfile with only two lines 可以轻松完成,创建一个文件夹,在其中创建my.cnf和仅两行的Dockerfile

FROM mysql
ADD my.cnf /path/to/mysql/conf/folder # replace with the path where you'd usually put the conf file

Now build and run: 现在构建并运行:

docker build -t custom_mysql .
docker run custom_mysql // << add the run options you need/want (exposed port for example or container name)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM