How To: Run a C# program in Docker on a PFC200

Create a directory on the PFC200 that you wish to use as your working directory.

Create a Dockfile in that directory containing:

FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim-arm32v7 AS build
WORKDIR /app
RUN dotnet new console
COPY MyFile.cs Program.cs
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/runtime:6.0-bullseye-slim-arm32v7
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT [“dotnet”, “app.dll”]

Create a C# program in that directory and save as MyFile.cs or use the simple program below:

// C# program to print Hello World!
using System;

// namespace declaration
namespace HelloWorldApp {

// Class declaration 
class Geeks { 
    
    // Main Method 
    static void Main(string[] args) { 
        
        // statement 
        // printing Hello World! 
        Console.WriteLine("Hello World!"); 
        
        // To prevents the screen from 
        // running and closing quickly 
        Console.ReadKey(); 
    } 
} 

}

You can name the C# program as you wish, just make sure the Dockerfile matches.

Run the following command to build the docker image:

docker build -t myimagename:arm32v7 .

Run the following command to test the Hello World program:

docker run -it myimagename:arm32v7

All the files and commands should be in the same directory.

Acknowledgement: Thanks go to Joe A. for his help in figuring this out.

4 Likes