How to setup the dotnet dev-certs on Linux without affecting the repository?

  .net-core, c#, docker, linux, ssl-certificate

I’m using Pop!_OS 20.04 LTS (based on Ubuntu) and want to run a .Net Web Api in a Docker container. Unfortunately I get this exception

Unable to start Kestrel. System.InvalidOperationException: Unable to
configure HTTPS endpoint. No server certificate was specified, and the
default developer certificate could not be found or is out of date. To
generate a developer certificate run ‘dotnet dev-certs https’. To
trust the certificate (Windows and macOS only) run ‘dotnet dev-certs
https –trust’. For more information on configuring HTTPS see
https://go.microsoft.com/fwlink/?linkid=848054.

when running the container with this docker-compose file

version: '3.9'
services:
  api:
    ports:
      - '443:443'
      - '80:80'
    image: api
    environment:
      - ASPNETCORE_URLS=https://+:443;http://+:80

and this Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /app

COPY *.csproj ./
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet
WORKDIR /app
EXPOSE 443 80
COPY --from=build /app/out .
ENTRYPOINT [ "dotnet", "Api.dll" ]

So Windows and Mac users can solve this problem pretty easily as described here

https://docs.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-5.0&tabs=visual-studio#trust-the-aspnet-core-https-development-certificate-on-windows-and-macos

but it seems Ubuntu users have to do it as described here

https://stackoverflow.com/a/59702094/7764329

I’m not sure if I should use this solution because in step 3 I would have to modify the appsettings.json file although I think my local setup shouldn’t affect the repository at all.

Many people are maintaining the repository so all of us would have to solve it "somehow" for their OS/machine.

Is there an equivalent for the

dotnet dev-certs https --trust

command for Linux users in 2021? This little solution is way more easier to keep in the "getting started wiki" than creating a big guide on how to setup the repository when working on Linux…

Source: Docker Questions

LEAVE A COMMENT