I have the following docker-compose.yamldocker-compose.yaml to roll my application. When I comment depends_on on newseo service, containers start with no issue and all healthchecks are passed. However, when I add depends_on back, newseo.api is stuck during its startup with no logs present as well as no connection to {url}/health.
Here is the docker-compose:
services:
newsseo:
image: ${DOCKER_REGISTRY-}newsseo
build:
context: .
dockerfile: NewsSEO/Dockerfile
depends_on:
newsseo-api:
condition: service_healthy
newsseo-api:
image: ${DOCKER_REGISTRY-}newsseoapi
build:
context: .
dockerfile: NewsSEO.API/Dockerfile
depends_on:
postgres:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "curl -k -f https://localhost:8081/health || exit 1"]
interval: 10s
timeout: 10s
retries: 3
postgres:
image: postgres:18.0
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: "admin123"
POSTGRES_USER: "admin"
POSTGRES_DB: "news_db"
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 10s
retries: 3
I have already added curl in the Dockerfile of newseo:
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
USER root
RUN apt-get update && apt-get install -y curl
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
Healthcheck in the code of newsseo-api is added with builder.Services.AddHealthChecks() and app.MapHealthChecks("health").
Things I already tried:
- Changing https 8081 to http 8080 in the healthcheck.
- Increasing interval, timeout and start_period.
- Adding restart: on-failure to both services.