Member-only story
Deploy a Containerized ASP.NET Core App to Heroku using GitHub Actions

In this blog post, we will create a containerized ASP.NET Core 3 Web API project, and set up a CI/CD pipeline using GitHub Actions. In the GitHub workflow, we will build and test the Web API project, and deploy the final docker image to Heroku.
There are only several (not many, unfortunately) free hosting providers that support containerized ASP.NET Core applications. One of them is ZEIT, which offers *.now.sh
domain names. Another one is Heroku, which is a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud. In this project, we will host our application in Heroku, which provides *.herokuapp.com
domain names.
Prerequisite
I assume you have already built an ASP.NET Core application. If not, please follow the tutorial (link) to create a Web API project, and follow the tutorial (link) to create a unit testing project. Moreover, you can follow this tutorial (link) to add Swagger support for your API documentation.
I have created a simple ASP.NET Core 3 Web API project, called “Colors.API
”, and a unit testing project, called “Colors.UnitTests
”. The complete solution can be found in this GitHub repository. (UPDATE: the solution has been updated to ASP.NET Core 5.0.)
In the following sections, we are going to
(1) add a Dockerfile
to containerize our application,
(2) create an app in heroku.com,
(3) add a GitHub workflow to build a docker image for our application, publish the image to the Heroku container registry, and release it to a container hosting environment in heroku.com .
Containerize the ASP.NET Core Application
Let’s add a file named “Dockerfile
” and a file named “.dockerignore
” to the root of this solution. The following screenshot shows the folder tree structure.

The content of the .dockerignore
file can be found here. Each item in the .dockerignore
file will be disregarded by the…