Skip to content

Instantly share code, notes, and snippets.

@JaimeStill
Created January 30, 2024 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaimeStill/ad183045fb34d25d98bf3b7b06d550fc to your computer and use it in GitHub Desktop.
Save JaimeStill/ad183045fb34d25d98bf3b7b06d550fc to your computer and use it in GitHub Desktop.
Register CA Certificates in .NET Web API Docker Image

Register CA Certificates in .NET Web API Docker Image

Create a .crt file in the root of the API project that contains the CA certificates.

Use the following Dockerfile configuration:

FROM mcr.microsoft.com/dotnet/sdk:latest AS base
WORKDIR /app

COPY . .
RUN dotnet nuget add source /app/nuget_packages -n "local"
RUN dotnet nuget remove source "nuget.org"
RUN dotnet publish -c Release -o out
RUN mv <cert-file>.crt /app/out

FROM mcr.microsoft.com/dotnet/aspnet:latest
EXPOSE 80
EXPOSE 443
ENV ASPNETCORE_HTTP_PORTS=80
WORKDIR /app
COPY --from=base /app/out .
RUN mv <cert-file>.crt /usr/local/share/ca-certificates
RUN chmod 644 /usr/local/share/ca-certificates/<cert-file>.crt && update-ca-certificates
ENTRYPOINT ["dotnet", "<API>.dll"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment