Closed
Description
Sometimes I use a command like the following to initialize a mysql new database volume from a backup.
docker run --rm ... --volume /path/to/backup.sql:/docker-entrypoint-initdb.d/backup.sql mysql
It would be handy if I could (through a environment variable, alternative entrypoint, etc.) cause the docker container to stop running after the init process is complete, instead of listening for connections.
My current workaround (hack) is to build a new image based on the mysql image, that contains a shell script that waits for the init process to finish - and then kill the mysql service. This seems to work fine, but it would be nice if there was a baked in way to accomplish this behavior.
#!/bin/bash
set -e
# wait until init process is finished
until /docker-entrypoint.sh mysqld 2>&1 | \
tee /dev/tty | \
grep --silent --extended-regexp --max-count=1 "init process done|error";
do
sleep 1;
done
# shutdown container
kill -s TERM $$