invoiceninja / dockerfiles

Docker files for Invoice Ninja
https://hub.docker.com/r/invoiceninja/invoiceninja
GNU General Public License v2.0
418 stars 268 forks source link

Database Availability Race Condition during Intialisation #565

Open sierja opened 8 months ago

sierja commented 8 months ago

There is a race condition when bring up this stack with Docker Compose, the application will start before the MySQL instance is ready, preventing the schema being loaded and the seeding from occurring which poisons the stack's persistence.

The db service in the docker-compose.yml should have a health check, such as:

healthcheck:
  test: mysqladmin -p$$MYSQL_ROOT_PASSWORD ping -h localhost
  interval: 20s
  start_period: 10s
  timeout: 10s
  retries: 3

The app service in the docker-compose.yml should require db as a health dependency , such as:

depends_on:
  db:
    condition: service_healthy