Wednesday 15 November 2023

Installing .NET 8 Runtime on Ubuntu 22.04 Docker Image

 :NET 8 was release on November 14. There are docker container images for .NET 8 available for dotnet runtime and can be found with tag list here . However, if you want to setup .NET 8 runtime on another specific Linux docker image for example on ubuntu:jammy , amd64/ubuntu:22.04 or with a special image such as ffmpeg Linux server image linuxserver/ffmpeg:amd64-version-6.0-cli, where you might want to run your .NET app to use ffmpeg, In such cases, where you you might have to setup .NET 8 runtime on a specific docker image, with your other tools readily available, details mentioned may come in handy.   Lets, see how we can install .NET 8 runtime on base Ubuntu 22.04 images, using a docker file.

What you would need is below. This will install required dependencis as well as .NET 8 runtime on any of the above mentioned docker images.

You can copy code from below.

FROM ubuntu:jammy AS base

RUN apt-get update \
    && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        curl \
        ca-certificates \
        libc6 \
        libgcc1 \
        libgcc-s1 \
        libgssapi-krb5-2 \
        libicu70 \
        liblttng-ust1 \
        libssl3 \
        libstdc++6 \
        libunwind8 \
        zlib1g \
    && rm -rf /var/lib/apt/lists/*

RUN curl -sSL | bash /dev/stdin -Channel 8.0 -Runtime dotnet -InstallDir /usr/share/dotnet
RUN ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet

Instead of using the hopefully we will be able to use below when the packages are avaialble.

RUN apt-get install -y dotnet-runtime-8.0 # not available yet

 With this a dotnet app can be run on any of the above mentioned docker images for esample below console app code runs fine in linuxserver/ffmpeg:amd64-version-6.0-cli image and provide output as shown. This enables the .NET app to use ffmpeg in docker container without having us to set up ffmpeg by ourselves on a dotnet base docker image.

namespace videoprocessor.xabe;

class Program
    static void Main(string[] args)
        string? mediaPath = Environment.GetEnvironmentVariable("MEDIA_PATH");

        if (mediaPath is not null)
            string[] files = Directory.GetFiles(mediaPath);

            Console.WriteLine($"Media path is: {mediaPath}");
            Console.WriteLine($"Files: {files[0]}");

No comments:

Popular Posts