This is a weird one, but I guess they always are!
I have a custom image built on top of the Ubuntu 16.04 default image. This image runs the following web stack:
MySQL 14.14 Dist 5.7.19 with the Percona engine
My host machine runs Windows 10 Pro 1803
Tested with Docker CE For Windows 18.03.1 / 17513 and 18.06.0 / 19075
From this image, I’m manging a single container using docker-compose.
As part of a container startup script, the MySQL service is started (among other services) using a mounted volume with existing files. This works fine.
Then, I created a first-time script for new hosts without this volume so they can get set up quickly. The script effectively cleans out any existing data in MySQL’s data directory, initialises a fresh database, and boots MySQL.
The issue is that when the script is run from the host, the docker-compose exec line to boot up MySQL instance hangs and never returns control to the host. This is the command:
docker-compose exec -T webserver /bin/bash -c "service mysql start"
What’s just as bad is, any other docker-compose command to this container after this will also hang after executing, including interactively running a bash session. In the container, I can verify that MySQL is running and working, but if I exit then the script hangs forever. Additionally, I can’t CTRL+C to cancel out of the interactive / TTY view.
The only command which doesn’t hang afterwards, is a docker-compose command to stop the MySQL service. Similarly, if I’m accessing the container and stop the instance inside, then exit out, that doesn’t hang either.
I’ve not ran into this issue before because I’ve never needed to docker-compose exec to directly manage the mysql instance, but now I want to. The really stupid thing is, if I open a bash from docker compose and manually run
service mysql start inside the container, then exit out, everything still works fine. It’s only when the service is started directly as part of docker-compose. This also counts if the command is in a script and that script is run from docker-compose.
There’s a couple of questions on SO about docker hanging but none of them seem to be the same as this issue. It’s specifically mysql, and it’s only when it starts running from docker-compose.
I’ve tested this with a mounted data dir and just leaving it in the container, both have the same issue.
For now, I’ve worked around this issue by attempting to both initialise and start the MySQL instance on container boot, but I’d love to have help on why this is happening!