Deploy dotnet core app to heroku

An aspnet core web app/api app is assumed to have been implemented already. Following is how to deploy it.

Heroku PORT

Heroku saves in the environment variable PORT, the port where the application should listen. So the port needs to be changed to that one.

public static IHostBuilder CreateHostBuilder(string[] args) =>
      .ConfigureWebHostDefaults(webBuilder =>
          var herokuPort = Environment.GetEnvironmentVariable("PORT");
          if (!string.IsNullOrWhiteSpace(herokuPort))


FROM AS build-env

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o publish

# Build runtime image

COPY --from=build-env /app/publish .

ENTRYPOINT ["dotnet", "Bustroker.Notes.WebUI.dll"]

Build image, push and deploy to heroku using heroku cli and heroku containers registry.

An app is assumed to have been created in heroku site. Deployment can be done, as heroku explaines in their documentation, in various ways. Here’s one of them, using heroku container registry.

First install heroku cli

curl | sh

Login to heroku and heroku containers registry, using command line

heroku login -i
heroku container:login

Have heroku build and push the image to their registry

heroku container:push <REPOSITORY_NAME> --app <APP_NAME>

Deploy a container from the image pushed

heroku container:release <REPOSITORY_NAME> --app <APP_NAME>

Browse to (or curl) https://<APP_NAME>