IBM Data Server Drivers (Db2 Connect Client)

Steps to deploy Db2 .Net Core Applications on Docker Windows Server Core Container

By PrashanthRao Karnam posted Mon March 01, 2021 11:57 PM

  

Steps to deploy Db2 .Net Core Applications on Docker Windows Server Core Container

Microsoft Visual Studio 2017 supports writing applications which can be deployed on Docker.

Docker for Windows is available for install at

https://docs.docker.com/docker-for-windows/install/

By default, docker daemon will be pointing to linux containers. Make sure to switch to windows containers by right clicking on Docker icon from the Windows System Tray as shown in below image:

 

To know more about how to write a sample Db2 .Net Core MVC application, please refer  here

Windows Docker Containers are supported only with the IBM Db2 .Net Core Provider package version 3.1.0.100 and can be downloaded from here

Once you have application ready, follow below steps to deploy your application to Docker Windows Server Core Containers:

 

1) Right Click on the project to add the docker support as shown in the below screen shots :

 

 

 

2) A Dockerfile will be created. Now replace the contents of the file with the following.


# escape=`

FROM mcr.microsoft.com/windows/servercore:1809 AS build

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

# Retrieve .NET Core SDK

ENV DOTNET_SDK_VERSION 2.1.503

RUN Invoke-WebRequest -OutFile dotnet.zip https://dotnetcli.blob.core.windows.net/dotnet/Sdk/$Env:DOTNET_SDK_VERSION/dotnet-sdk-$Env:DOTNET_SDK_VERSION-win-x64.zip; `

    $dotnet_sha512 = '29e44a4d6bd81ace5f7f5b5be946e7fc81325f4563d375d6809150bfc0552c70e07467770c8c6b44127b5b1c01d93ca14e1c98ba527313dc093db8942358760c'; `

    if ((Get-FileHash dotnet.zip -Algorithm sha512).Hash -ne $dotnet_sha512) { `

        Write-Host 'CHECKSUM VERIFICATION FAILED!'; `

        exit 1; `

    }; `

    `

    Expand-Archive dotnet.zip -DestinationPath dotnet; `

    Remove-Item -Force dotnet.zip

RUN setx /M PATH $($Env:PATH + ';C:\dotnet')

WORKDIR /src

COPY ["testdb2aspcoreapp/testdb2aspcoreapp.csproj", "testdb2aspcoreapp/"]

RUN dotnet restore "testdb2aspcoreapp/testdb2aspcoreapp.csproj"

# copy and build everything else

COPY . ./

WORKDIR "/src/testdb2aspcoreapp"

RUN dotnet build testdb2aspcoreapp.csproj -c Release -o /app

FROM build AS publish

RUN dotnet publish -c Release -o /app

# Final Application Deployment image

FROM mcr.microsoft.com/windows/servercore:1809 as final

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

COPY --from=build ["C:/dotnet", "C:/Program Files/dotnet/"]

# In order to set system PATH, ContainerAdministrator must be used

USER ContainerAdministrator

RUN setx /M PATH $($Env:PATH + ';C:\Program Files\dotnet')

USER ContainerUser

WORKDIR /app

COPY --from=publish /app .

# Configure web servers to bind to port 80 when present

ENV ASPNETCORE_URLS=http://+:80 `

    # Enable detection of running in a container

    DOTNET_RUNNING_IN_CONTAINER=true `

    # Enable correct mode for dotnet watch (only mode supported in a container)

    DOTNET_USE_POLLING_FILE_WATCHER=true `

    # Skip extraction of XML docs - generally not useful within an image/container - helps performance

    NUGET_XMLDOC_MODE=skip `

   #set the db2 language which is needed for db2 .net core applications to work on Windows Server Core Docker Containers

    DB2LANG=en_US

#Expose the ports which are mapped between host and container

EXPOSE 80

EXPOSE 63580

EXPOSE 6050

# Trigger first run experience by running arbitrary cmd to populate local package cache

ENTRYPOINT ["dotnet.exe", "testdb2aspcoreapp.dll"]
 
3) Make sure to change the project name and solution name as per your project and solution name accordingly in the DockerFile

4) Now select “Docker” from the deployment target options, the docker commands will be run from the dockerfile and application will be hosted on a docker Windows Server Core container:

To know how to deploy Db2 .Net Core applications on Docker Linux Containers, please refer here

0 comments
10 views

Permalink