I have 2 services: service-background & service-webapi. Those are registered in docker-compose. Service-background needs to be started up first. Only then service-webapi may be booted. This is a fixed order. I have following configuration in docker-compose.yml:
networks:
my-fantastic-network
services:
background-service:
build: backgroundproject
networks:
my-fantastic-network:
aliases:
-background-service
webapi-service:
build: webapi
depends_on:
-background-service
networks:
my-fantastic-network:
aliases:
-webapi-service
I thought this would be enough to let the webapi-service wait for the background-service but this one starts up too soon and messes up totally.
My background-service has a log file in following file structure: server/database/logs/startup.log If the log file contains the text "Database initialized successfully", the background-service is ready and the webapi-service can startup safely. I could use the Linux grep function to check if my logfile contains this specific text. But I don't know how to do this with docker-compose.
I did some research and there is a healthcheck attribute available to use in docker-compose, but I'm not too familiar with it.
Can someone help me?