-2

I have the following docker-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:

  1. Changing https 8081 to http 8080 in the healthcheck.
  2. Increasing interval, timeout and start_period.
  3. Adding restart: on-failure to both services.
4
  • If you remove the depends_on: line and all of the services do start, does the health check pass? Does newsseo-api have a dependency on newsseo; does the newsseo-api health check try to make an HTTP call to newsseo that's needed for it to start up successfully? Commented Nov 13 at 13:48
  • What port(s) do newsseo-api listen on? The default for ASP.NET apps is to only listen on port 8080. EXPOSE doesn't do anything, so you can't take those ports at face value. ASP.NET applications usually print out what ports they listen on when they start, so you should be able to find the port number(s) in the container logs. Commented Nov 13 at 13:53
  • @DavidMaze yes, if I remove or comment depends_on, then all services start. Furthermore, when I exec the exact command in the container when it's properly started, I get "Healthy" response. Commented Nov 13 at 14:24
  • @HansKilian ports are assigned at random by Visual Studio. Although, I doubt that this should affect the problem. Even if I hardlock api on a particular port, it does not resolve the issue. Commented Nov 13 at 14:29

1 Answer 1

1

Turns out the problem is specific to how docker-compose.dcproj file that manages docker compose project. DependencyAwareStart is required to manage dependencies of .NET containers in the docker-compose project. Here is the full XML:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
  <PropertyGroup Label="Globals">
    <ProjectVersion>2.1</ProjectVersion>
    <DockerTargetOS>Linux</DockerTargetOS>
    <DockerPublishLocally>False</DockerPublishLocally>
    <DependencyAwareStart>True</DependencyAwareStart>
    <ProjectGuid>81dded9d-158b-e303-5f62-77a2896d2a5a</ProjectGuid>
    <DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
    <DockerServiceUrl>{Scheme}://localhost:{ServicePort}</DockerServiceUrl>
    <DockerServiceName>newsseo</DockerServiceName>
  </PropertyGroup>
  <ItemGroup>
    <None Include="docker-compose.override.yml">
      <DependentUpon>docker-compose.yml</DependentUpon>
    </None>
    <None Include="docker-compose.yml" />
    <None Include=".dockerignore" />
  </ItemGroup>
</Project>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.