After docker + mysql restart can not change the configuration of the solution
Premise: In a recent project, decided to transform the project into a separate database schema to read and write, so unauthorized changes to the configuration file database production environment my.cnf
, because I was deployed with a docker, execution docker restart mysql
and found not up, execution docker logs -f --tail 10 your-mysql
, appears as follows mistake:
Here I mention that docker restart mysql
basically will not cause data loss (except under high concurrency scenarios). Do not panic, since the profile wrong, I like change overnight, so I execute docker exec -it mysql /bin/bash
ready to enter the container and then change the configuration, find the entrance! ! Because the exec command applies only to vessels that are running.
Within a group of flustered ah! ! !
Fortunately, in time to find the relevant information, the database will be successfully restarted.
Solutions
method one
Store configuration information docker container in the current host (usually the default directory is: / var / lib / docker / overlay /), then just find the configuration file, you can modify after restart
Second way
Use docker cp command to copy docker container configuration file to the host in the past, and then you modify and then copied to the docker container to go on it
Specific operation
After the practical operation, the way a way can be tricky, only describes the second approach here.
1, in the docker container file copied to the host machine
docker cp mysql:/etc/mysql/my.cnf .
Note: The representative is the current directory, when I operate the current directory is / opt
2, vim modify the local configuration file errors, re-edit back
3, the modified configuration file to copy the container to docker
docker cp my.cnf mysql:/etc/mysql/my.cnf
4, container instances restart
docker restart db002