Created
June 9, 2022 06:33
-
-
Save lox/41de39b36cdef4275abcfa12c09d9719 to your computer and use it in GitHub Desktop.
MySQL in Docker seems slow to start 🤔
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
wait_for_container() { | |
echo -n "Waiting for $1" | |
for _ in $(seq 1 120); do | |
test "$(docker inspect --format "{{.State.Health.Status}}" "$1")" == "healthy" && break | |
sleep 1 | |
echo -n . | |
done | |
echo | |
if test "$(docker inspect --format "{{.State.Health.Status}}" "$1")" != "healthy" ; then | |
echo "error: $1 did not become ready" 1>&2 | |
exit 1 | |
fi | |
} | |
docker run -d --rm --name mysql -p 3306:3306 \ | |
--health-cmd='mysqladmin ping --silent' \ | |
-e MYSQL_ALLOW_EMPTY_PASSWORD=true \ | |
-e MYSQL_LOG_CONSOLE=true \ | |
-e MYSQL_ROOT_HOST=% \ | |
public.ecr.aws/docker/library/mysql:5.7 \ | |
--sql-mode="" --log-bin --binlog-format=ROW --server-id=1 | |
time wait_for_container mysql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment