Skip to content

Docker Containers

From MIKE OPERATIONS 2022.1, MIKE OPERATIONS support using the MIKE OPERATIONS API for running maintenence tasks in Docker Containers using MIKE OPERATIONS NuGet packages (versions >= 12.1).

Project file

The easiest way to create Docker images using the MIKE OPERATIONS API, is using a Visual Studio project.

The project file should use the .NET project SDK Microsoft.NET.Sdk, targeting the .NET 6.0 Framework or later and install NuGet packages as needed. Note that packages used should target .NET Standard 2.0 and/or .NET 6.0 as the project.

The sample project file below, installs the time series manager package and the MIKE Cloud time series provider. The package Npgsql is required to access PostgreSQL databases.

The runtime identifier RuntimeIdentifier is added for running the project on Windows while testing.

Code in the project (e.g. in a Program.cs file), can use the API provided by the NuGet packages. Please refer to the MIKE OPERATIONS API section.

The project file below are targeting .NET 6.0 on the Linux platform.

Important

Note that the DHI.MikeCore.Linux.rhel7 package is required when targeting the Linux platform.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

  <PropertyGroup>
    <PlatformTarget>x64</PlatformTarget>
    <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="DHI.MikeOperations.TimeseriesManager" Version="15.0.0" />
    <PackageReference Include="DHI.MikeOperations.TimeseriesManager.Provider.MikeCloud" Version="15.0.0" />
    <PackageReference Include="DHI.MikeCore.Linux.Ubuntu" Version="22.1.0" />
    <PackageReference Include="Npgsql" Version="5.0.18" />
  </ItemGroup>

</Project>  

Dockerfile

MIKE OPERATIONS has been tested on Docker images based on the Debian Linux distribution version 10 and 11 for .NET 6.0 published by Microsoft in the Microsoft Container Registry (MCR).

Available Linux images from Microsoft can be found on .NET Runtime

The runtime images are for project execution and the SDK image is for building the project in the container image.

.NET Image Variants

Info

Container images based on Alpine will NOT work with the MIKE OPERATIONS NuGet packages as well as with MIKE1D NuGet packages.

Please visit the Microsoft Supported Tags Documentation on how container images are named.

Debian

Debian systems currently use the Linux kernel or the FreeBSD kernel. Linux is a piece of software started by Linus Torvalds and supported by thousands of programmers worldwide. FreeBSD is an operating system including a kernel and other software.

Debian versions

Debian 11 (Bullseye)

.NET 6.0 base container images from the MCR has been tested using MIKE OPERATIONS 2023 and 2024 NuGet packages.

Deprecated images

  • mcr.microsoft.com/dotnet/runtime:6.0-bullseye-slim (MIKE OPERATIONS 2023 and 2024)
  • mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim (MIKE OPERATIONS 2023 and 2024)

Debian 12 (Bookworm)

Base container images released by Microsoft with .NET 8.0 in November 2023.

These images has be tested and is supported with MIKE OPERATIONS 2024.2.

  • mcr.microsoft.com/dotnet/runtime:8.0-bookworm-slim (MIKE OPERATIONS 2024.2)
  • mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim (MIKE OPERATIONS 2024.2)

Deprecated images

  • mcr.microsoft.com/dotnet/runtime:6.0-bookworm-slim (MIKE OPERATIONS 2024)
  • mcr.microsoft.com/dotnet/sdk:6.0-bookworm-slim (MIKE OPERATIONS 2024)

Debian 10 (Buster) - Deprecated!

Base container images with .NET 5.0 from the MCR was tested using MIKE OPERATIONS 2022 NuGet packages.

  • mcr.microsoft.com/dotnet/runtime:5.0-buster-slim (MIKE OPERATIONS 2022)
  • mcr.microsoft.com/dotnet/sdk:5.0-buster-slim (MIKE OPERATIONS 2022)

Warning

.NET 5.0 and Debian 10 has been deprecated by Microsoft and should no longer be used in container images.

Ubuntu 20 and 22 (Focal and Jammy)

Base container images with .NET 6.0 will also work.

  • mcr.microsoft.com/dotnet/runtime:6.0-jammy
  • mcr.microsoft.com/dotnet/sdk:6.0-jammy
  • mcr.microsoft.com/dotnet/runtime:6.0-focal
  • mcr.microsoft.com/dotnet/sdk:6.0-focal
  • mcr.microsoft.com/dotnet/runtime:8.0-jammy
  • mcr.microsoft.com/dotnet/sdk:8.0-jammy

### Red Hat Base container images with .NET 6.0 will also work.

  • registry.access.redhat.com/ubi8/dotnet-60-runtime

Dockerfile Sample

A docker file is always named Dockerfile without a file extension.

The Dockerfile below shows how to build and execute a project named MO.Core.Test.

# Debian 11 (Bullseye) as base images
FROM mcr.microsoft.com/dotnet/runtime:6.0-bullseye-slim AS base
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim AS build

# Make Sure that the image is up to date.
RUN apt-get update && apt-get install -y && apt-get dist-upgrade -y

# Set the working directory
WORKDIR /app

# Copy the project file and files included in the project to the container image (project here named MO.Core.Test).
COPY MO.Core.Test.csproj .
COPY ./Program.cs .

# Restore NuGet packages used from both NuGet.org and from the internal DHI package feed.
RUN dotnet restore -s "http://dhi-nuget-server.azurewebsites.net/nuget" -s "https://api.nuget.org/v3/index.json" "./MO.Core.Test.csproj"

# Publish the image using the linux-x64 runtime to the app/out folder
RUN dotnet publish -c Release -r linux-x64 -f net6.0 -o out

# Set the time zone of the image if the image always runs in a certain time zone (e.g. "America/New_York", "GMT-1" or "CET" for Central Eurepean time).
#ENV TZ="CET"

# Set runtime base image as the final image to limit the size of the container image.
FROM base AS final
RUN apt-get update && apt-get install -y && apt-get dist-upgrade -y

# Install Python 3.11 as used by the CPython Engine of MIKE OPERATIONS 2024.
# Python versions 3.7 to 3.12 are supported with MIKE OPERATIONS 2024.
RUN apt-get update || : && apt-get install python3.11 -y
RUN apt-get install -y python3-pip

WORKDIR /app/out
COPY --from=build /app/out .

# Set the shared library path LD_LIBRARY_PATH so that it includes /app/out, to make sure  that native DLL's published (e.g. DHI.EUM files) can be found during execution.
# ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/app/out"
ENV LD_LIBRARY_PATH /app/out

# Set MIKE environment variables so that the MIKE software license can be checked when starting the application.
ENV MIKE_LICENSE /app/out/NetLmLcwConfig.xml
ENV MIKE_HOME /app/out

# Generate the license configuration file using an internet license or a network license.
RUN /app/out/licconfig set --type=internet --iuser=[e-mail] --ipassword=[password] --file=/app/out/NetLmLcwConfig.xml
#RUN /app/out/licconfig set --type=network --server=[servername or ip] --file=/app/out/NetLmLcwConfig.xml

# Set the working directory to the project ouput directory and execute the published project.
WORKDIR /app/out

# Runs the project
CMD dotnet MO.Core.Test.dll

Build Container Images

Before running a container image in a container, the container image should be build.

Use the following command to build an image called testcontainerimage01

docker build . -t testcontainerimage01
  • The . after the build keyword tells that Docker should look for the Dockerfile in the current directory.
  • The -t flag tags the image with a readable name using lower case (here testcontainerimage01).

Please refer to the docker command CLI documentation for more information on building docker images.

Note that images to be published to the DHI Container Registry, should be tagged with the registry name dhiacrdev.azurecr.io prefix. The dev in dhiacrdev indicates that the container image is published in the Development environemt.

E.g. dhiacrdev.azurecr.io/mo/mo_test02:0.9 containing the following format dhiacr<environment>.azurecr.io/<image name>:<version>.

Run Containers

To run a docker docker container, use the keyword run.

The following command will run a Docker container image named testcontainerimage01.

docker run -a STDOUT -a STDIN testcontainerimage01

To run e.g. a specic command.

docker run -a STDOUT -a STDIN testcontainerimage01 "/bin/sh" "-c" "dotnet MO.Core.Test.dll"

or running a Python script (when Python has been installed):

docker run -a STDOUT -a STDIN testcontainerimage01 "/bin/sh" "-c" "python test.py"

With arguments

docker run -a STDOUT -a STDIN testcontainerimage01 "/bin/sh" "-c" "python test.py arg1 arg2"

Please refer to the docker command CLI documentation for more information on running docker images.

Publish Images to the DHI ACR

To allow Docker images to be executed using the DHI Platform Job Service, container images should be published to the Azure Container Registry (ACR) of DHI.

Refer to the DHI Platform documentation for detailed information on how to publish here. Please follow these steps.

  • Install the Azure Commandline Interface (CLI)
  • Login to the Azure AD
  • Get Access Token
  • Docker Login
  • Push Image

Login to AD

Before trying to login to the Azure AD, access should be granted by the DHI Platform team. Please contact a member of the team.

Use the following command in PowerShell.

az login

Use the -t parameter to force login to a specified tenant.

az login -t <tenant id>

Associate account

The account should be associated to the Azure substription to publish containers to (e.g. DHI - MIKE - DEV)

az account set --subscription="DHI - MIKE - DEV"

Get access Token

An access token is needed for the Docker login.

az acr login -n dhiacrdev --expose-token

Docker login

Login to dhiacrdev.azurecr.io using the access token.

docker login dhiacrdev.azurecr.io --username=00000000-0000-0000-0000-000000000000 -p <access token>

Note

Note that the Docker client should be started before logging in to Docker.

Buildcontainer image

Build the container image.

docker build . -t dhiacrdev.azurecr.io/dhi-mycontainerimage

Push Container Image

Images to be published to the DHI Azure Container Registry, should be tagged with the ACR name dhiacrdev.azurecr.io as prefix.

The following sample shows how to publish such an image.

docker push dhiacrdev.azurecr.io/dhi-mycontainerimage

The name format looks like this <ACR name>/<image name>:<version>.

IronPython scripts

IronPython scripts stored in MIKE OPERATIONS, can be executed as long as code written in the script, is using API's available as NuGet packages targeting .NET Standard 2.0 (e.g. most MO modules).

The package DHI.MikeOperations.ScriptManager.IronPython contains required IronPython libraries.

CPython scripts

CPython scripts stored in MIKE OPERATIONS, can be executed as long as code written in the script, is using API's available as NuGet packages targeting .NET Standard 2.0 (e.g. most MO modules).

The package DHI.MikeOperations.ScriptManager.CPython contains Python libraries included in the MIKE OPERATIONS installation.

Note

Note that the MIKE OPERATIONS container image deployed to the DHI Cloud Platform container repository, only contains default Python 3.9 libraries/modules. This means that only script using default Python libraries/modules can currently be used when running jobs using the DHI Cloud Platform job service.