Deploy ASP.Net Core to Heroku for free using Docker

Mai
2 min readAug 28, 2019

--

Today, I’ll show you how I deployed my ASP.Net Core web application named “ExampleNetcore” to Heroku using Docker.

Login to heroku and heroku container using these comand line:
heroku login
heroku container:login

Create a new app by this command line:
heroku apps:create examplenetcore
You can choose any app name if it wasn’t taken.

In your working directory, run this command line:
dotnet publish -c Release
My release directory should be like this:

Release directory

In the publish directory, create a Dockerfile like this:
FROM microsoft/dotnet:2.2-aspnetcore-runtime
WORKDIR /app
COPY . .
CMD ASPNETCORE_URLS=
http://*:$PORT dotnet ExampleNetcore.dll
You can change the version to which is suitable with your app. In this case, I use aspnetcore 2.2.
The ExampleNetcore is my project name so you should change it to yours.

publish directory have Dockerfile

Then build docker image by running this command line:
docker build -t examplenetcore ./bin/release/netcoreapp2.2/publish

build success

Tag and push docker image using these command line:
docker tag examplenetcore registry.heroku.com/examplenetcore/web
docker push registry.heroku.com/
examplenetcore/web
Notice that examplenetcore is the heroku app name.

push success

Finally, release container to heroku by this command line:
heroku container:release web -a examplenetcore

release to heroku success

Open heroku app with link: https://examplenetcore.herokuapp.com/

Hope this post help you something.

--

--