Deploy Your .NET 7 Application to Heroku With Docker

Alejandro Dominguez
The Startup
Published in
3 min readJul 20, 2020

--

Deploying a Docker image on Heroku is a straightforward process, yet certain nuances require attention. This article will provide a comprehensive, step-by-step guide to avoid setbacks.

Photo by Guillaume Bolduc on Unsplash

Prerequisites:

Create your web application:

First, we will create a new MVC application with .NET Core 3.1 Framework and run it to see that everything went correctly.

Create new app

If everything went well we should be able to navigate through the default address https://localhost:5001

Build your docker image:

Create a file called Dockerfile in the root of your application. And build your image.

If you’re acquainted with Docker files, you might question the absence of any port EXPOSEd. This omission is deliberate since Heroku manages the port, primarily for security considerations. Consequently, we need to modify our application code to properly receive requests on the port designated by Heroku.

Please make adjustments to your Program.cs file as demonstrated in the following example.

If you do not include line (2), you will probably get an error when you app is deploy:

Unable to start Kestrel. System.Net.Sockets.SocketException (13): Permission denied

Host your application with Heroku

Create new app:

Go to Heroku Dashboard and create your application.

Login:

First we have to install Heroku CLI on our PCs. Then log in to your Heroku account and follow the prompts to create a new SSH public key.

Log in to Container Registry:

Make sure you have Docker well configured.

Push your Docker-based app:

Build the Dockerfile in the current directory and push the Docker image. Don’t forget to specify your application name using the -a option.

Release your app:

Release the newly pushed images to deploy your app.

Check the logs:

Take a look the application logs and check that everything looks correct.

All done!

Everything ready, we already have our online application with just executing a few steps. If you need to configure environment variables you can do it in: Application> Settings> Config Vars

Protect Your Online Privacy with NordVPN

Disclosure: This section contains promotional content.

NordVPN is a Virtual Private Network (VPN) service that provides users with a secure and private way to access the internet.

In today’s digital era, safeguarding online security and privacy is paramount. With rising cyber threats and data breaches, protecting sensitive information is crucial. Enter NordVPN — a potent tool ensuring secure and private online browsing.

👉 NordVPN: Get up to 65% discount with our NordVPN promotion code

👉 NordLocker: Get up to 53% discount with our NordLocker promotion code

👉 NordPass: Get up to 50% discount with our NordPass promotion code

Note: Discounts may vary overtime; check official NordVPN sites for current offers.

More than a VPN, NordVPN empowers your online presence. In a privacy-threatened age, using NordVPN means safety and contributing to a secure online world. For more info, assistance is available here.

--

--