Skip to content

Docker

Note

Only applible for WebAPIs

All the DS Web API components target .NET Standard 2.0 and are thus truly cross platform. They can be used with any .NET runtime - including .NET Core. So indeed you could set up an ASP.NET Core project targeting the .NET Core runtime, install and configure DS Web API components and deploy it as a Docker container based on an ASP.NET Core image.

However, because most of the technology-specific providers, such as the MIKECore provider and the PostgreSQL provider, require the .NET Framework runtime, the DS Web API project templates target the .NET Framework runtime. So a project based on the DS Web API projects templates must be deployed as a Docker container based on an ASP.NET Framework image.

The below recipe describes how to containerize a DS Web API project.

1) To allow remote connection on Kestrel, add the following lines in the Program.cs file of your project:

2) Create a dockerfile

The following base images are used:

  • microsoft/dotnet-framework:4.7.2-runtime-windowsservercore-1803 for the sake of the providers that are using .NET Framework
  • microsoft/dotnet:2.2-sdk-nanoserver-1809 for the sake of the Web APIs
# escape=`

FROM microsoft/dotnet:2.2-sdk-nanoserver-1809 AS dotnet
FROM microsoft/dotnet-framework:4.7.2-runtime-windowsservercore-1803  AS base

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

ENV DOTNET_PATH="C:\Program Files\dotnet" 

COPY --from=dotnet ${DOTNET_PATH} ${DOTNET_PATH}

RUN $env:PATH = $env:DOTNET_PATH + ';' + $env:PATH; `

    [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine)

WORKDIR /app

COPY . .

ENTRYPOINT ["DomainServices.Timeseries.API.exe"]

3) Put dockerfile on publish folder (in Visual Studio right click project - Publish)

4) Run docker build -t domainservices.timeseries.api

5) Run docker run -d -p 8080:80 --name domainservices.timeseries.api domainservices.timeseries.api:latest (port 80 is used for app inside container, mapped to port 8080 on host machine)