Single-File Executables in .NET Core 3.1 and the Quest for a Sub-50MB Docker Container

Single-File Executables in .NET Core 3.1 and the Quest for a Sub-50MB Docker Container

There were a few requirements on this journey. These are goals I set for myself in order to push the limits of .NET Core during this experiment. Linux Environment Only: These micro-services will be deployed in Docker containers on Kubernetes, so a Linux environment was a must.Tiny Container Footprint: Getting .NET Core down to under 10MB was most likely not in the cards, but the target was 50MB.

I’ve been building .NET Core Web API micro-services for a while now and have been loving it. However, when it came to Docker image size, it did not hold a candle to a Golang API using a SCRATCH base image. Some of my production images that are written in .NET Core 2.0 were typically coming in around 200–300MB. While Go is fast and compiles down amazingly well, I find that the language and tooling leaves a bit to be desired and sometimes I still long for Visual Studio and all its syntactic sugar. With the release of .NET Core 3.1 LTS last year, I decided it was finally time to revisit using it to build a tiny WebAPI container.

There were a few requirements on this journey. These are goals I set for myself in order to push the limits of .NET Core during this experiment.

  • Linux Environment Only: These micro-services will be deployed in Docker containers on Kubernetes, so a Linux environment was a must.
  • Tiny Container Footprint: Getting .NET Core down to under 10MB was most likely not in the cards, but the target was 50MB.
  • No Multi-Stage Dockerfile: Most examples online of .NET Core APIs in containers use a multi-stage Dockerfile. I did not want this requirement as part of the project. Multi-stage Docker builds are great, but introduce complexity and time. Plus, with .NET Core 3.0, this just isn’t needed anymore.
  • MacOS Development Environment: My development environment is macOS, so this is a hard requirement for me.

Scaffolding the WebAPI

Let’s get started with building out a base .NET Core WebAPI in Visual Studio. We’ll use the “New Project” wizard and select “API” from the “.NET Core App” left hand nav.

dotnet-core docker docker container .net core 3.1 linux

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

jQuery Ajax CRUD in ASP.NET Core MVC with Modal Popup

In this article, we’ll discuss how to use jQuery Ajax for ASP.NET Core MVC CRUD Operations using Bootstrap Modal. With jQuery Ajax, we can make HTTP request to controller action methods without reloading the entire page, like a single page application.

gRPC & ASP.NET Core 3.1: How to create a gRPC service ?

You’ll need to open Visual Studio 2019 and select “gRPC service” in “Create a new project” screen: gRPC & ASP.NET Core 3.1: How to create a gRPC service ? – Anthony Giretti's .NET blog

New - Updates .NET Core January 2020(2.1.15, 3.0.2, and 3.1.1)

.NET Core 3.1.1 is available for download and usage in your environment. This release includes .NET Core 3.1.1 and .NET Core SDK 3.1.101.

Entity Framework Core in ASP.NET Core 3.1

We will learn about entity framework core in details i.e. what, how & why and see how to use it in ASP.NET Core Web API to implement CRUD operations. Though here we will be using entity framework in ASP.NET Core this can be implemented even in .NET Framework for your data persistence.

Microservices with ASP.NET Core 3.1

This article will cover in detail how to create Microservices with ASP.NET Core with Serilog, Exception Handling, Swagger UI, Health Checks & Docker.