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

Prerequisites

Introduction

Implementation of .NET Core Web API Application

Step 1

Create a new .NET Core Web API application

Hosting .NET Core Web API images with Docker Compose over HTTPS

Step 2

Configure your application

Hosting .NET Core Web API images with Docker Compose over HTTPS

Step 3

Provide additional information

Hosting .NET Core Web API images with Docker Compose over HTTPS

Step 4

Hosting .NET Core Web API images with Docker Compose over HTTPS

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

Step 7

Step 8

Next, in the docker desktop, you can see the application is running inside the docker container

Hosting .NET Core Web API images with Docker Compose over HTTPS

Also, inside the visual studio, we can see the details of containers as shown in the below images

Hosting .NET Core Web API images with Docker Compose over HTTPS

Hosting .NET Core Web API images with Docker Compose over HTTPS

Hosting .NET Core Web API images with Docker Compose over HTTPS

Step 9

Finally, open both application URLs and use the application

http://localhost:8081/swagger/index.html

Hosting .NET Core Web API images with Docker Compose over HTTPS

https://localhost:8082/swagger/index.html

Hosting .NET Core Web API images with Docker Compose over HTTPS

GitHub URL

https://github.com/Jaydeep-007/HTTPSCertDemo.git

Conclusion

In the article, we discussed HTTPS and how to enable that when we run applications inside the docker container using both ways, firstly using the docker command and secondly using the docker-compose file with the help of the .NET Core Weather forecast application.

Happy Learning!