I cannot figure out how to fully start ubuntu/mysql, prepare the db, execute tests, and exit the container. Here is my docker file:
FROM ubuntu/mysql:latest
COPY my_db_scripts.sql /docker-entrypoint-initdb.d/
COPY my_test.sh /tests
WORKDIR /tests
I am running it with the following command:
docker run --rm -it -p 3306:3306 -e MYSQL_ROOT_PASSWORD=cool my_tests:1.0.0
The my_db_scripts.sql completes successfully. However, if I add my_tests.sh as an ENTRYPOINT or CMD at the end of the Dockerfile, the test scripts execute before mysql listener starts. If I add my_tests.sh to /docker-entrypoint-initdb.d/, the script executes after the temp mysql instance stops, as quoted in the documentation:
All of this is done before the MySQL service is started. Keep in mind if your database directory is not empty (contains pre-existing database) they will be left untouched.
How can I wait for mysql to start, execute my_tests.sh, and stop the container? ( i.e my test scripts will return error or no error based on results )
Links I used to try different things:
Executing SQL scripts on docker container
How do I know when my docker mysql container is up and mysql is ready for taking queries?