Requirements

Docker Heroku CLI (you will need registered Heroku account) ASP.Net Core application you want to deploy (I will use the one we've created here)

Create Heroku App

Setup Dockerfile

# First we add a dotnet SDK image to build our app inside the container FROM microsoft/dotnet:sdk AS build-env WORKDIR /app # Copy csproj and restore as distinct layers COPY *.csproj ./ RUN dotnet restore # Copy everything else and build COPY . ./ RUN dotnet publish -c Release -o out # Here we use ASP.NET Core runtime to build runtime image FROM microsoft/dotnet:aspnetcore-runtime WORKDIR /app COPY --from=build-env /app/out . CMD ASPNETCORE_URLS=http://*:$PORT dotnet NetCoreExample.dll

ENTRYPOINT ["dotnet", "NetCoreExample.dll"]

CMD ASPNETCORE_URLS=http://*:$PORT dotnet NetCoreExample.dll

NetCoreExample.dll

Deploy Docker Container to Heroku

$ heroku login $ heroku container:login

$ docker build -t netcoreexample .

netcoreexample

$ docker tag netcoreexample registry.heroku.com/test-app-docker/web

test-app-docker

$ docker push registry.heroku.com/test-app-docker/web﻿

$ heroku container:release web -a test-app-docker

Summary

Today I want to make a small and simple blog post about how to deploy ASP.Net Core application to Heroku using Docker.To start, we need to create a blank app from Heroku like thisChoose the name you like and then we are good to go.Re-use dockerfile from my previous post : Because Heroku doesn’t work nicely withcommand we should change this:to this:And don't forget to changeto the name of your application.First, we need to login to Heroku and Heroku container using these commands:While I was doing this, I was constantly getting an error "docker: Got permission denied while trying to connect to the Docker...". If you also get this error, check this StackOverflow question. Now we should build Docker image using this command:Whereis the name of your app.We need to tag the heroku target imageWhereis the name of the Heroku app, we've created on the first step.Push the docker image to Heroku registryAnd finally deploy it!Now if you will open link that loos like https://{your-app-name}.herokuapp.com/ you will be able to access you web app.Now you can use only 4 commands to deploy your application to Heroku. In future you can add CI system and configure it to do them for you ;)Thank you for reading and Happy Coding!