Does docker compose does not start services in parallel

0

I guess docker-compose up can start multiple services in parallel (REF).

I have an application that depends on multiple services (e.g., database). The application is implemented in ASP.NET Core, and uses Polly for resiliency; e.g., wait for database for a certain time intervals, if a given exception is thrown, re-try connecting to database for a given number of times before throwing an exception.

var policy = Policy
    .Handle<HttpRequestException>()
    .WaitAndRetryAsync(new[] { 
        TimeSpan.FromSeconds(1), 
        TimeSpan.FromSeconds(2), 
        TimeSpan.FromSeconds(4) 
    });

When I start the project using docker-compose up, I expect Polly to try connect to database, but since database is not ready yet, it should wait for few seconds and re-try, and hopefully after few retries database is ready and it can connect. However, it seems docker-compose up does not start services in parallel, because does not matter for how many times Poly retires and how long it waits (e.g., even hours), the database is not start when my application service is waiting/retrying, and the database service starts immediately after my application and tried/waited for a given period and has thrown an exception.

I am defining docker compose as:

version: '3.7'

services:

  sql.data:
    container_name: db_service
    image: microsoft/mssql-server-linux:2017-latest

  my_service:
    container_name: my_service_container
    image: ${DOCKER_REGISTRY-}my_service
    build:
      context: .
      dockerfile: MyService/Dockerfile
    depends_on:
      - sql.data

and the log looks like:

Recreating db_service ... done
Recreating my_service_container ... done
Attaching to db_service, my_service_container 
my_service_container | info: ...Context[0]
my_service_container |       Migrating database associated with context Context
my_service_container | info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
my_service_container |       Entity Framework Core 3.1.1 initialized 'Context' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: MigrationsAssembly=MyService
my_service_container | fail: Context[0]
my_service_container |       An error occurred while migrating the database used on context Context
my_service_container | Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)
...
EXCEPTION DETAILS ... 
MANY RETRIES AND WAITS
...
my_service_container | ClientConnectionId:00000000-0000-0000-0000-000000000000
my_service_container exited with code 0
db_service | 2020-03-05 05:45:51.82 Server      Microsoft SQL Server 2017 (RTM-CU13) (KB4466404) - 14.0.3048.4 (X64)
        Nov 30 2018 12:57:58
        Copyright (C) 2017 Microsoft Corporation
        Developer Edition (64-bit) on Linux (Ubuntu 16.04.5 LTS)
2020-03-05 05:45:51.82 Server      UTC adjustment: 0:00
2020-03-05 05:45:51.82 Server      (c) Microsoft Corporation.
2020-03-05 05:45:51.82 Server      All rights reserved.
2020-03-05 05:45:51.82 Server      Server process ID is 4120.
2020-03-05 05:45:51.82 Server      Logging SQL Server messages in file '/var/opt/mssql/log/errorlog'.
2020-03-05 05:45:51.82 Server      Registry startup parameters:
         -d /var/opt/mssql/data/master.mdf
         -l /var/opt/mssql/data/mastlog.ldf
         -e /var/opt/mssql/log/errorlog

Note the comment above, it seems the database service has not even started before my application has retried/waited and then failed.

Am I missing something in the docker, or docker-compose?

c#
docker
asp.net-core
docker-compose
asked on Stack Overflow Mar 5, 2020 by Hamed

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0