I've created new ASP.net Core 2.1 project in Visual Studio 2019. I've choosed to generate Docker linux container and docker-compose file. Everything's working fine when I'm using VS to run it.
The problem appears when I try to run my app in production-like environment. In order to do that, I've git-cloned code onto targer linux machine. Then I run docker-compose up
in folder of my project.
At first it didn't work, because app uses HTTPS and there were no HTTPS certificates for localhost on machine. I needed to generate certificate:
dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p crypticpassword
In docker-compose.yml
I've specified a volume to link folder with certificate to folder inside docker container where my app looks for certificates (last line of below code).
version: '3.4'
services:
mongo:
# not relevant
mongo-express:
# not relevant
synceddb:
image: ${DOCKER_REGISTRY-}synceddb
ports:
- 13000:13000
- "10002:80"
- "44361:443"
build:
context: .
dockerfile: SyncedDB/Dockerfile
depends_on:
- mongo
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_HTTPS_PORT=44361
- ASPNETCORE_Kestrel__Certificates__Default__Password="crypticpassword"
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
volumes:
- ${HOME}/.aspnet/https:/https/
Dockerfile looks as follows:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
WORKDIR /src
COPY ["SyncedDB/SyncedDB.csproj", "SyncedDB/"]
RUN dotnet restore "SyncedDB/SyncedDB.csproj"
COPY . .
WORKDIR "/src/SyncedDB"
RUN dotnet build "SyncedDB.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "SyncedDB.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "SyncedDB.dll"]
The problem is: my app doesn't see my certificate (at least it's how I interpret this error)
crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
Interop+Crypto+OpenSslCryptographicException: error:2006D080:BIO routines:BIO_new_file:no such file
at [...]
Unhandled Exception: Interop+Crypto+OpenSslCryptographicException: error:2006D080:BIO routines:BIO_new_file:no such file
[...]