Docker Community Forums

Share and learn in the Docker community.

Docker-Compose Issues with ASP.NET Core 2.2 and SQL Server 2017

I am using Docker (v19.03.1) in conjunction with with Visual Studio 2019 (v16.2.0) and .NET Core 2.2.

I have created a yml file:

version: "3.7"
services:
    web:
        build:
            dockerfile: SnowdonAPI_05/Dockerfile
            context: .
        ports:
            - '8080:80'
        depends_on:
            - db
    db:
        image: 'mcr.microsoft.com/mssql/server:2017-latest'
        ports:
            - '1433:1433'
        volumes:
            - 'C:\DockerVolumes:/var/opt/mssql/data'
        environment:
            SA_PASSWORD: 'Sample1234$'
            ACCEPT_EULA: 'Y'

To note: I had to escape th $ using $ which I trust is correct according to the logs

Here is the Dockerfile for my Web Api:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["SnowdonAPI_05/SnowdonAPI_05.csproj", "SnowdonAPI_05/"]
RUN dotnet restore "SnowdonAPI_05/SnowdonAPI_05.csproj"
COPY . .
WORKDIR "/src/SnowdonAPI_05"
RUN dotnet build "SnowdonAPI_05.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "SnowdonAPI_05.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "SnowdonAPI_05.dll"]

The service seems to say its build and running (0 warnings and 0 errors), but it hangs when configuring SQL. Apologies as here is all the output from Powershell after running docker-compose up --build :

PS C:\Repos\SnowdonAPI_05\SnowdonAPI_05> docker-compose up --build
Building web
Step 1/16 : FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
 ---> 3ee0429b27ad
Step 2/16 : WORKDIR /app
 ---> Using cache
 ---> 15fa3b5679ff
Step 3/16 : EXPOSE 80
 ---> Using cache
 ---> 93bec482a2a0

Step 4/16 : FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
 ---> 3af77ac73731
Step 5/16 : WORKDIR /src
 ---> Running in 5661fe0d8c7c
Removing intermediate container 5661fe0d8c7c
 ---> ac5e7dec8c47
Step 6/16 : COPY ["SnowdonAPI_05/SnowdonAPI_05.csproj", "SnowdonAPI_05/"]
 ---> 66f47ad09e52
Step 7/16 : RUN dotnet restore "SnowdonAPI_05/SnowdonAPI_05.csproj"
 ---> Running in bb0f11670454
  Restore completed in 2.57 sec for /src/SnowdonAPI_05/SnowdonAPI_05.csproj.
Removing intermediate container bb0f11670454
 ---> 2611471633df
Step 8/16 : COPY . .
 ---> 2c08764b9d70
Step 9/16 : WORKDIR "/src/SnowdonAPI_05"
 ---> Running in 169c8ce2a91d
Removing intermediate container 169c8ce2a91d
 ---> 6470eb779abb
Step 10/16 : RUN dotnet build "SnowdonAPI_05.csproj" -c Release -o /app
 ---> Running in cbdef20c3f04
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 35.1 ms for /src/SnowdonAPI_05/SnowdonAPI_05.csproj.
  SnowdonAPI_05 -> /app/SnowdonAPI_05.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.63
Removing intermediate container cbdef20c3f04
 ---> 00fe7581aff0

Step 11/16 : FROM build AS publish
 ---> 00fe7581aff0
Step 12/16 : RUN dotnet publish "SnowdonAPI_05.csproj" -c Release -o /app
 ---> Running in ecd2f2ff048c
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 34.97 ms for /src/SnowdonAPI_05/SnowdonAPI_05.csproj.
  SnowdonAPI_05 -> /src/SnowdonAPI_05/bin/Release/netcoreapp2.2/SnowdonAPI_05.dll
  SnowdonAPI_05 -> /app/
Removing intermediate container ecd2f2ff048c
 ---> daf4a3d889fc

Step 13/16 : FROM base AS final
 ---> 93bec482a2a0
Step 14/16 : WORKDIR /app
 ---> Using cache
 ---> d668ec1d7025
Step 15/16 : COPY --from=publish /app .
 ---> Using cache
 ---> 8b1806961ab8
Step 16/16 : ENTRYPOINT ["dotnet", "SnowdonAPI_05.dll"]
 ---> Using cache
 ---> 60f80a0ad682

Successfully built 60f80a0ad682
Successfully tagged snowdonapi_05_web:latest
Starting snowdonapi_05_db_1 ... done                                                                                                                          Starting snowdonapi_05_web_1 ... done                                                                                                                         Attaching to snowdonapi_05_db_1, snowdonapi_05_web_1
web_1  | Hosting environment: Production
web_1  | Content root path: /app
web_1  | Now listening on: http://[::]:80
web_1  | Application started. Press Ctrl+C to shut down.
db_1   | 2019-08-08 10:27:38.88 Server      Microsoft SQL Server 2017 (RTM-CU16) (KB4508218) - 14.0.3223.3 (X64)
        Jul 12 2019 17:43:08
        Copyright (C) 2017 Microsoft Corporation
        Developer Edition (64-bit) on Linux (Ubuntu 16.04.6 LTS)
2019-08-08 10:27:38.88 Server      UTC adjustment: 0:00
2019-08-08 10:27:38.89 Server      (c) Microsoft Corporation.
2019-08-08 10:27:38.89 Server      All rights reserved.
2019-08-08 10:27:38.89 Server      Server process ID is 28.
2019-08-08 10:27:38.89 Server      Logging SQL Server messages in file '/var/opt/mssql/log/errorlog'.
2019-08-08 10:27:38.89 Server      Registry startup parameters:
         -d /var/opt/mssql/data/master.mdf
         -l /var/opt/mssql/data/mastlog.ldf
         -e /var/opt/mssql/log/errorlog
2019-08-08 10:27:38.90 Server      SQL Server detected 1 sockets with 1 cores per socket and 2 logical processors per socket, 2 total logical processors; using 2 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
2019-08-08 10:27:38.90 Server      SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2019-08-08 10:27:38.91 Server      Detected 1600 MB of RAM. This is an informational message; no user action is required.
2019-08-08 10:27:38.91 Server      Using conventional memory in the memory manager.
2019-08-08 10:27:39.11 Server      Buffer pool extension is already disabled. No action is necessary.
2019-08-08 10:27:39.24 Server      InitializeExternalUserGroupSid failed. Implied authentication will be disabled.
2019-08-08 10:27:39.25 Server      Implied authentication manager initialization failed. Implied authentication will be disabled.
2019-08-08 10:27:39.25 Server      Successfully initialized the TLS configuration. Allowed TLS protocol versions are ['1.0 1.1 1.2']. Allowed TLS ciphers are ['ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:!DHE-RSA-AES256-GCM-SHA384:!DHE-RSA-AES128-GCM-SHA256:!DHE-RSA-AES256-SHA:!DHE-RSA-AES128-SHA'].
2019-08-08 10:27:39.30 Server      The maximum number of dedicated administrator connections for this instance is '1'
2019-08-08 10:27:39.30 Server      Node configuration: node 0: CPU mask: 0x0000000000000003:0 Active CPU mask: 0x0000000000000003:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
2019-08-08 10:27:39.31 Server      Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.
2019-08-08 10:27:39.32 Server      In-Memory OLTP initialized on lowend machine.
2019-08-08 10:27:39.37 Server      Database Instant File Initialization: enabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required.
ForceFlush is enabled for this instance.
2019-08-08 10:27:39.38 Server      Query Store settings initialized with enabled = 1,
2019-08-08 10:27:39.39 Server      Software Usage Metrics is disabled.
2019-08-08 10:27:39.40 spid6s      Starting up database 'master'.
ForceFlush feature is enabled for log durability.
2019-08-08 10:27:39.86 spid6s      Service Master Key could not be decrypted using one of its encryptions. See sys.key_encryptions for details.
2019-08-08 10:27:39.89 spid6s      An error occurred during Service Master Key initialization. SQLErrorCode=33095, State=8, LastOsError=0.
2019-08-08 10:27:39.93 spid6s      Resource governor reconfiguration succeeded.
2019-08-08 10:27:39.94 spid6s      SQL Server Audit is starting the audits. This is an informational message. No user action is required.
2019-08-08 10:27:39.94 spid6s      SQL Server Audit has started the audits. This is an informational message. No user action is required.
2019-08-08 10:27:39.96 Server      Failed to verify the Authenticode signature of 'C:\binn\secforwarder.dll'. Signature verification of SQL Server DLLs will be skipped. Genuine copies of SQL Server are signed. Failure to verify the Authenticode signature might indicate that this is not an authentic release of SQL Server. Install a genuine copy of SQL Server or contact customer support.
2019-08-08 10:27:40.07 spid6s      SQL Trace ID 1 was started by login "sa".
2019-08-08 10:27:40.09 spid6s      Server name is '95886e6262be'. This is an informational message only. No user action is required.
2019-08-08 10:27:40.12 spid20s     Always On: The availability replica manager is starting. This is an informational message only. No user action is required.
2019-08-08 10:27:40.13 spid20s     Always On: The availability replica manager is waiting for the instance of SQL Server to allow client connections. This is an informational message only. No user action is required.
2019-08-08 10:27:40.15 spid23s     Starting up database 'msdb'.
2019-08-08 10:27:40.16 spid9s      Starting up database 'mssqlsystemresource'.
2019-08-08 10:27:40.17 spid25s     Starting up database 'snowdon'.
2019-08-08 10:27:40.18 spid9s      The resource database build version is 14.00.3223. This is an informational message only. No user action is required.
2019-08-08 10:27:40.22 spid9s      Starting up database 'model'.
2019-08-08 10:27:40.38 spid18s     A self-generated certificate was successfully loaded for encryption.
2019-08-08 10:27:40.40 spid18s     Server is listening on [ 'any' <ipv6> 1433].
2019-08-08 10:27:40.40 spid18s     Server is listening on [ 'any' <ipv4> 1433].
2019-08-08 10:27:40.41 Server      Server is listening on [ ::1 <ipv6> 1434].
2019-08-08 10:27:40.41 Server      Server is listening on [ 127.0.0.1 <ipv4> 1434].
2019-08-08 10:27:40.41 Server      Dedicated admin connection support was established for listening locally on port 1434.
2019-08-08 10:27:40.42 spid18s     SQL Server is now ready for client connections. This is an informational message; no user action is required.
2019-08-08 10:27:40.89 spid25s     Parallel redo is started for database 'snowdon' with worker pool size [1].
2019-08-08 10:27:41.03 spid9s      Polybase feature disabled.
2019-08-08 10:27:41.03 spid9s      Clearing tempdb database.
2019-08-08 10:27:41.06 spid6s      Parallel redo is shutdown for database 'snowdon' with worker pool size [1].
2019-08-08 10:27:42.00 spid9s      Starting up database 'tempdb'.
2019-08-08 10:27:42.46 spid9s      The tempdb database has 1 data file(s).
2019-08-08 10:27:42.47 spid20s     The Service Broker endpoint is in disabled or stopped state.
2019-08-08 10:27:42.47 spid20s     The Database Mirroring endpoint is in disabled or stopped state.
2019-08-08 10:27:42.51 spid20s     Service Broker manager has started.
2019-08-08 10:27:42.55 spid6s      Recovery is complete. This is an informational message only. No user action is required.
2019-08-08 10:32:44.08 spid51      Attempting to load library 'xplog70.dll' into memory. This is an informational message only. No user action is required.
2019-08-08 10:32:44.12 spid51      Using 'xplog70.dll' version '2017.140.3223' to execute extended stored procedure 'xp_msver'. This is an informational message only; no user action is required.

I then have to CTRL + C to gracefully stop the two containers.

I thought it was related to my Volume mount but it looks as though its connecting:

2019-08-08 10:27:40.15 spid23s     Starting up database 'msdb'.
2019-08-08 10:27:40.16 spid9s      Starting up database 'mssqlsystemresource'.
2019-08-08 10:27:40.17 spid25s     Starting up database 'snowdon'.

As snowdon is the name of the DB. Any ideas?

UPDATE

I have changed my service to use SQL 2019 and the same thing happens!

Here is my yml :

version: "3.7"
services:
    web:
        build:
            dockerfile: SnowdonAPI_05/Dockerfile
            context: .
        ports:
            - '8080:80'
        depends_on:
            - db
    db:
        image: 'mcr.microsoft.com/mssql/server:2019-latest'
        ports:
            - '1433:1433'
        volumes:
            - 'C:\DockerVolumes\2019:/var/opt/mssql/data'
        environment:
            SA_PASSWORD: 'Sample1234$'
            ACCEPT_EULA: 'Y'