My goal is to up and running multiple containers on docker with https using asp net webapi. So far I successufully ran one webapi container with https followed steps in this article:
Hosting ASP.NET Core images with Docker over HTTPS
When I try to add https to second container while sending request my second webapi container stops when first container works as expected.
How to achieve adding https certificate to all asp net webapi containers?
My docker-compose.yml looks like below:
# Please refer https://aka.ms/HTTPSinContainer on how to setup an https developer certificate for your ASP .NET Core service.
version: '3.4'
services:
app1:
image: app1
container_name: app1
build:
context: .
dockerfile: source/app1/Dockerfile
ports:
- 6000:5000
- 6001:443
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:6001
- ASPNETCORE_Kestrel__Certificates__Default__Password=password
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
volumes:
- ~/.aspnet/https:/https:ro
app2:
image: app2
container_name: app2
build:
context: .
dockerfile: source/app2/Dockerfile
ports:
- 6002:5000
- 6003:443
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:6003
- ASPNETCORE_Kestrel__Certificates__Default__Password=password
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
volumes:
- ~/.aspnet/https:/https:ro
and Dockerfile of app1:
FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal AS base
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
WORKDIR /src
COPY ["source/app1/app1.csproj", "source/app1/"]
RUN dotnet restore "source/app1/app1.csproj"
COPY . .
WORKDIR "/src/source/app1"
RUN dotnet build "app1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "app1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "app1.dll"]
and Dockerfile of app2:
FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal AS base
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
WORKDIR /src
COPY ["source/app2/app2.csproj", "source/app2/"]
RUN dotnet restore "source/app2/app2.csproj"
COPY . .
WORKDIR "/src/source/app2"
RUN dotnet build "app2.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "app2.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "app2.dll"]