Docker Community Forums

Share and learn in the Docker community.

MySQL container crash/stop on service restart

Hi,

I’m a comparative newbie to Docker, and have hit an issue I can’t find online help for.

We’re running Docker version 18.09.6, build 481bc77 inside an AWS EC2 instance (M3.Large).

One container is running MySQL Community Server 5.6.44 in a configuration that doesn’t include general MySQL logging. I want to change the MySQL config file to check that I can get logging going, and then eventually, change the image with a change to that single config file. It’s easy to make the config file edits once I install vim in the container, but when I use ‘service mysql restart’, the entire container stops or crashes immediately, and (as expected) on restart, the config file change is gone.

When I use ’ service mysql status’, it returns…
[info] MySQL Community Server 5.6.44 is running.

which tells me that the ‘service’ command works, at least partially.

Using ‘service mysql stop’ also crashes/stops the container

Is this expected behaviour? If so, how do i set it up so I can experiment with configuration options without building a new container for each one - or how do I make short-term changes for experiments on a running container if the ‘service’ command stops it?

Thanks,

Paul

MySQL runs in the foreground, see the last command in the Dockerfile: CMD ["mysqld"]
This foreground process tells the Docker engine that the container is alive. If it disappears this means the container has stopped.
It should be no big thing to stop and restart containers (that’s their fundamental idea).
For MySQL you can do the following: create a local folder or a volume that contains your config file. On startup of the container mount it to /etc/mysql/conf.d. To change it stop the container, edit the file, restart the db. You find some more informations in the docs of the mysql image in the section “Using a custom MySQL configuration file”.

1 Like

Wow…thanks, Tekki. That all makes perfect sense…and is very simple to do!