Open file inside docker container has been shut do

2019-08-15 01:06发布

问题:

I start a mysql container and change the config file inside a container, in this case is /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?

回答1:

A container is immutable, your changes and conf are gone. You should use a Dockerfile to build a custom image and include my.cnf.

It can be easily done, create a folder, create my.cnf in it and a Dockerfile with only two lines

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)