We are going to discuss here SSL Certificate configuration for secure communication over the HTTPS using .NET Core Web API and Docker after running our application inside the docker container using docker-compose.
Agenda
- Introduction
- Implementation of .NET Core Web API Application
- Generate a certificate for secure communication
- Containerization of application
Prerequisites
- Visual Studio 2022
- Docker Desktop
- .NET Core 6 SDK
Introduction
- HTTPS is a standard internet protocol that makes the data to be encrypted and a more advanced and secure version of the HTTP protocol.
- SSL stands for Secure Sockets Layer and standard technology which keeps secure our application over the internet.
- SSL is the part of HTTPS protocol and it takes care of the encryption of data.
- It enables a secure connection and prevents hacker attacks because of its encryption algorithm and many security layers.
Implementation of .NET Core Web API Application
Step 1
Create a new .NET Core Web API application

Step 2
Configure your application

Step 3
Provide additional information

Step 4
- Next, we create a certificate for the local machine using the following command
dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\dockerdemo.pfx -p Pass@***** dotnet dev-certs https --trust
- Here as you can see, we pass the certificate name and password in the above command and it will create the certificate at %USERPROFILE%\.aspnet\https this location

Step 5
Create a Docker file for our Weather Forecast application
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app
EXPOSE 443
EXPOSE 80
# copy project csproj file and restore it in docker directory
COPY ./*.csproj ./
RUN dotnet restore
# Copy everything into the docker directory and build
COPY . .
RUN dotnet publish -c Release -o out
# Build runtime final image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "HTTPSCertDemo.dll"]
Step 6







Justin NPosted Mar 19, 2023, 3:46 AM
I have the same setup but have issues with the docker compose volume.Error response from daemon: invalid volume specification: 'C:\Users\epon\.aspnet\https:/https:ro'