Ubuntu: deploy .NET Core app

Today, I want to walk-through the steps I used to deploy ASP.NET Core website application to Ubuntu Server. ASP.NET Core supports several Linux distributions, I am using Ubuntu Server.

From a quick internet search I found 3 decent blog posts:

  1. decatechlabs.com article
  2. garywoodfine.com article
  3. blog.bobbyallen.me post

There already are many articles which talk about how to set up your development environment for .NET Core but this post starts, where they end. It’s about getting production ready.

These are to-the-point & well written. But, either these posts are more than a year old, or they are for setting up your development environment, not for production deployment. You need to install .NET Core run-time, not the .NET Core SDK (which also includes run-time). You can download it from:  https://www.microsoft.com/net/download (Available for Linux, Windows & Mac)

Now, for the demo purpose, I would use the default website:

$ dotnet new mvc

12 days ago, Microsoft announced .NET Core 2.1. I am running on version 2.1.201. One of the new things in 2.1 is the additional template support – whetting your appetite 😉

The new .NET Core templates, in .NET Core 2.1

$ dotnet run

… and the website is up and spinning:

dotnet mvc app running

Joie de vivre!

It all starts with installation. At the time of writing this, I am using Ubuntu Server 18.04 LTS, so I will be following these instructions for installing .NET Core run-time, in Ubuntu. Notice that, in the last command we are installing runtime, instead sudo dotnet-sdk-2.1.

Before installing .NET, you’ll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.

Open a command prompt and run the following commands:

$ wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
$ sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
$ wget -q https://packages.microsoft.com/config/ubuntu/18.04/prod.list 
$ sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
$ sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
$ sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list

Install .NET Core runtime (not SDK)

$ sudo apt-get install apt-transport-https
$ sudo apt-get update
$ sudo apt-get install aspnetcore-runtime-2.1

You might ask, what is the difference between a runtime and SDK?

The resources required to build applications that target .NET Core, using command line tools and any editor.

The resources required to run existing applications built with .NET Core.

Evidently, it means run-time has a smaller footprint.

Virtual Box users

(You can skip this section if you are not using Virtual Box.) I don’t want to use the tiny screen of my Virtual Box (granted that in Ubuntu, I can easily change this in GRUB config, but I don’t want to monkey with my server.) The image below shows the 3 simple steps I used to SSH into guest OS (Ubuntu Server) from host OS (Ubuntu Desktop) terminal.

  1. Install VirtualBox utilities on the guest OS
  2. Add port forwarding in VirtualBox
  3. SSH login from host OS

SSH into guest OS. Screenshot: https://i.imgur.com/vUuYnCE.png

(full size ◳)

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s