2

Django and PostgreSQL with Docker Compose: the web container starts before the database is ready

TA Tunde Adeyemi 131 il y a 2 semaines Nigeria

On docker compose up, Django crashes with connection refused because Postgres is still initialising.

Modifiée il y a 1 heure
5
OO Otieno Odhiambo 35 · il y a 2 semaines

As an extra safety net, make your entrypoint script retry the connection a few times before running migrations.

1
MB Mamadou Barry 115 · il y a 2 semaines

depends_on only waits for the container to start, not for the database to accept connections. Add a healthcheck to the database service and make the web service depend on condition: service_healthy:

db:
  healthcheck:
    test: ["CMD-SHELL", "pg_isready -U postgres"]
    interval: 5s
    retries: 10

Vous connaissez la réponse ? Rejoignez Griot pour aider.

Publier

Poser une question Obtenir de l'aide de la communauté Publier un composant Partager un SDK, un wrapper ou un package Proposer un troc Échanger une heure d'aide contre une autre Créer une prime Récompenser une solution en Mobile Money Organiser un hackathon Lancer un défi pour la communauté
Troc de compétences Primes Hackathons Observatoire