I've spent some hours investigating this problem and I got a solution.
Docker depends_on
just consider service startup to run another service. Than it happens because as soon as db
is started, service-app tries to connect to ur db
, but it's not ready to receive connections. So you can check db
health status in app service to wait for connection. Here is my solution, it solved my problem. :)
Important: I'm using docker-compose version 2.1.
version: '2.1'
services:
my-app:
build: .
command: su -c "python manage.py runserver 0.0.0.0:8000"
ports:
- "8000:8000"
depends_on:
db:
condition: service_healthy
links:
- db
volumes:
- .:/app_directory
db:
image: postgres:10.5
ports:
- "5432:5432"
volumes:
- database:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
volumes:
database:
In this case it's not necessary to create a .sh file.
I hope it helps you guys ;)
cya
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…