Skip to content

Instantly share code, notes, and snippets.

@lox
Created June 9, 2022 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lox/41de39b36cdef4275abcfa12c09d9719 to your computer and use it in GitHub Desktop.
Save lox/41de39b36cdef4275abcfa12c09d9719 to your computer and use it in GitHub Desktop.
MySQL in Docker seems slow to start 🤔
#!/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