Slim .Net Containers

This Slim Starter Kit will show you how to build a .Net Hello World application and use the Slim platform to secure it for production.
sk-g sk-g

Hello .Net Core developers!

Optimize and harden your containerized applications the easy way — with Slim.AI.

This Starter Kit will help you proactively remove vulnerabilities from your applications.

Simply replace the application code here with your own application, run it through Slim.AI's automated container optimization process, and you'll remove up to 100-percent of the image's vulnerabilities while also making it up to 8.82X smaller.

No more chasing down hard to patch vulns that your application isn't even using, and you can use any base image you want — even mcr.microsoft.com/dotnet/sdk:latest.

Optimization Results

Result of optimized .NET image

Slimming this Rails container results in 100-percent reduction in overall vulnerabilities.

Vulnerability difference by severity

Result of vulnerability reduction .NET image

Get Started

To start a .Net Core application application, you'll need the following libraries installed locally, or running in a dev environment link GitPod, Docker Environments, or Code Spaces.

dotnet-sdk:6.0

To run locally use:

dotnet run

Sample Application

Our sample application is a simple REST API that merely returns "Hello World" JSON.

While this app is simple, it's a great starting point for more complex development.

Project structure

├── appsettings.Development.json
├── appsettings.json
├── Controllers
│   └── HelloWorldController.cs
├── Dockerfile
├── HelloApi.csproj
├── HelloWorld.cs
├── Program.cs
├── Properties
│   └── launchSettings.json
├── README.md

Code sample

    [HttpGet(Name = "HelloWorld")]
    public HelloWorld Get()
    {
        return new HelloWorld
        {
            Date = DateTime.Now,
            Hello = "World !"
        };
    }

Replace this placholder code with your own application code, and install any necessary dependencies, to create your own slimmable container.

Sample Dockerfile

Our Dockerfile builds off of the mcr.microsoft.com/dotnet/sdk:6.0 image and starts at 781MB.

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o out
WORKDIR /app/out
EXPOSE 5001
ENTRYPOINT ["dotnet", "HelloApi.dll","--urls=http://0.0.0.0:5001/"]

The slimming process reduces the size by 8.82X to just 88MB.

Try it yourself on Slim.AI