From 300c0de298a06a1621fc62480a85b54222b8741a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=CC=A6tefan=20Sa=CC=86ftescu?= Date: Tue, 22 Oct 2024 18:21:31 +0100 Subject: [PATCH] Wait for db when starting with docker-compose Add `pg_isready` as a healthcheck on the `db` service, and conditioned the start of the `memorymaptoolkit` service on the `db` service being healthy. This prevents the mapping service starting before the database is ready to receive connections. --- docker-compose.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 08f89de..10fa5c0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,11 @@ services: - 5433:5432 env_file: - .env + healthcheck: + test: [ "CMD-SHELL", "pg_isready" ] + interval: 10s + timeout: 5s + retries: 5 memorymaptoolkit: image: memorymaptoolkit build: @@ -29,7 +34,8 @@ services: - backups:/app/backups - .:/app depends_on: - - db + db: + condition: service_healthy command: python manage.py runserver 0.0.0.0:8000 --settings=memorymap_toolkit.settings.local ports: - 8000:8000 @@ -49,4 +55,4 @@ volumes: postgres_data: static: media: - backups: \ No newline at end of file + backups: