Containerizing and Hosting a .NET Core Application on Render: A Step-by-Step Guide

Karo Edaware
6 min readSep 13, 2023

--

Introduction

In today’s fast-paced world of software development, containerization has become a game-changer. It allows developers to build, package, and deploy applications consistently across different environments, ensuring seamless deployment and scalability. In this article, we’ll explore how to create a .NET Core application, containerize it using Docker, and eventually host it on the Render platform.

Prerequisites: Before we dive in, you should have a basic understanding of Visual Studio, .NET Core, and Docker. This tutorial primarily focuses on Visual Studio for Windows, but fear not, the principles we cover can be applied to other operating systems as well, and you can replicate the process using Visual Studio Code.

Let’s embark on this journey to learn how to develop, containerize, and deploy .NET Core applications with confidence!

Setting up the Development Environment

Before we can embark on our journey to containerize a .NET Core application, it’s essential to set up the right development environment. In this section, we’ll guide you through installing Visual Studio for Windows and .NET Core, which are the key tools we’ll be using.

Installing Visual Studio for Windows

Visual Studio is a powerful integrated development environment (IDE) that streamlines the development process. You can download and install Visual Studio for Windows by following the official installation guide provided by Microsoft here.

Once you’ve completed the installation, make sure to configure it according to your preferences and check for any available updates.

Creating a .NET Core Application

In this section, we will walk through the process of creating a .NET Core application using Visual Studio, which we will later containerize with Docker. Follow these steps:

Step 1: Launch Visual Studio

Step 2: Create a New Project

  • Click on “Create a new project” to begin.
Create a new project

Step 3: Search and Select ASP.NET Core Web MVC

  • In the project creation wizard, search for “ASP.NET Core Web MVC” and select it. This is the project type we’ll use for this article. Note that with Docker, you can use any .NET Core project type, but we’ll focus on this one.
Selecting ASP.NET Core MVC project

Step 4: Type the Project Name

  • Type a name for your project and click “Next.” You can choose any project name you like.

Step 5: Select the .NET Framework and Enable Docker

  • In this step, select the .NET framework you prefer. Ensure that you enable Docker and select the Docker OS installed on your PC. If you haven’t installed Docker yet, follow this link to set it up: Docker Installation Guide. It’s essential to note that Render doesn’t directly host .NET applications, so we’ll use Docker to overcome this limitation.

For this article, we’ll use a Linux container, but don’t worry; we won’t be running the project as a Docker image.

Step 6: Docker Configuration

  • Once the project is created, Visual Studio will add a Dockerfile. Here’s what’s inside it. You can learn more about Docker in Visual Studio .NET Core here.

Visual Studio will attempt to create the Docker image. If your Docker is running, it will create it. However, we don’t need to run it as a Docker container for this project. Change the startup project from Docker to HTTP. This means you don’t need Docker running for your application to run.

Docker as start up project
http as start up project

Step 7: Push Your Project to GitHub

  • It’s a good practice to add source control to your project. Follow this link to learn how to push your project to a GitHub repository. This step is crucial because Render will fetch your project from GitHub for hosting.

Step 8: Create a Render Account

  • If you haven’t already, create a Render account by following this link.

Step 9: Create a New Web Service on Render

  • In your Render dashboard, create a new Web Service. Use the repository you created on GitHub.
  • On the deployment screen, pick a name for your service. We recommend using Docker for the environment. The URL for your application will be created using this service name. Please note that the service name can be changed if necessary, but the initially created URL cannot be edited.
  • Click “Save Web Service,” and that’s it! Your service will begin building and should be live in a few minutes at the URL displayed in your Render dashboard. You can follow its progress in the deploy logs.
Build and deploy from github

Note: If you’ve encountered an issue with your first deployment on Render, don’t worry. You might face a hiccup due to the location of the Dockerfile in an ASP.NET Core project created with Visual Studio.

To resolve this, follow these steps:

  1. Go to the settings of your Render web service.
  2. Find the “Dockerfile Path” field and change it from ./dockerfile to ./your_reponame/dockerfile.
Edit docker file path.

This adjustment ensures that Render can locate your Dockerfile correctly, and your deployment should proceed without any issues. It’s a minor tweak, but it makes a significant difference in the deployment process.

With these steps, your .NET Core application is now hosted on Render.

Conclusion

In this tutorial, we’ve embarked on a journey to create, containerize, and host a .NET Core application on the Render platform. We began by setting up our development environment, using Visual Studio for Windows, and installing the necessary tools like .NET Core and Docker.

We then created a .NET Core application using the ASP.NET Core Web MVC template, an excellent starting point for web-based projects. Although we enabled Docker during the project setup, we didn’t run our application as a Docker image, showcasing the flexibility of the development environment.

We also emphasized the importance of source control by pushing our project to GitHub, a practice that simplifies deployment and collaboration. Render, our chosen hosting platform, seamlessly integrates with GitHub, allowing us to effortlessly deploy our application.

Render provides an excellent solution for hosting .NET Core applications, even though .NET Core applications aren’t directly supported. By leveraging Docker, we overcame this limitation, and our application is now live on the web.

As you continue your journey in software development, remember the power of containerization and cloud-based hosting platforms like Render. These tools empower developers to build, deploy, and scale applications with ease, ensuring a smooth and efficient development process.

Now that you’ve successfully containerized and hosted your .NET Core application, you’re well-equipped to tackle more complex projects and explore the vast possibilities of modern software development. Happy coding!

--

--

Karo Edaware

Full-stack developer specializing in .NET. Crafting high-performance solutions and exploring Flutter for cross-platform excellence.