Невозможно выполнить https-вызов из одного докер-контейнера в другой в Docker Compose в .Net 8. ⇐ C#

Место общения программистов C#
Anonymous
Невозможно выполнить https-вызов из одного докер-контейнера в другой в Docker Compose в .Net 8.

Сообщение Anonymous »

В Windows я создал проект .NET 8 под названием ApiOne в Visual Studio, включил контейнеры Linux и HTTPS и добавил оркестрацию контейнеров. Затем я добавил к тому же решению второй проект .NET 8, ApiTwo, также с поддержкой и оркестрацией контейнеров Linux. Хотя я могу отправлять HTTP-запросы от ApiOne к ApiTwo, HTTPS-запросы между ними не выполняются.
ApiOne Dockerfile:

Код: Выделить всё

# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

# Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
# For more information, please see https://aka.ms/containercompat

# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/aspnet:8.0-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0-nanoserver-1809 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["ApiOne/ApiOne.csproj", "ApiOne/"]
RUN dotnet restore "./ApiOne/ApiOne.csproj"
COPY .  .
WORKDIR "/src/ApiOne"
RUN dotnet build "./ApiOne.csproj" -c %BUILD_CONFIGURATION% -o /app/build

# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./ApiOne.csproj" -c %BUILD_CONFIGURATION% -o /app/publish /p:UseAppHost=false

# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ApiOne.dll"]
Запуск ApiOneSettings.json:

Код: Выделить всё

{
"profiles": {
"http": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5116"
},
"https": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7088;http://localhost:5116"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Container (Dockerfile)": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": true
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:22890",
"sslPort": 44373
}
}
}
Файлы ApiOne и ApiTwo похожи.

docker-compose .yml:

Код: Выделить всё

services:
apione:
image: ${DOCKER_REGISTRY-}apione
build:
context: .
dockerfile: ApiOne\Dockerfile

apitwo:
image: ${DOCKER_REGISTRY-}apitwo
build:
context: .
dockerfile: ApiTwo\Dockerfile

docker-compose.override.yml:

Код: Выделить всё

services:
apione:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_HTTP_PORTS=8080
- ASPNETCORE_HTTPS_PORTS=8081
ports:
- "8080"
- "8081"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:C:\Users\ContainerUser\AppData\Roaming\Microsoft\UserSecrets:ro
- ${APPDATA}/ASP.NET/Https:C:\Users\ContainerUser\AppData\Roaming\ASP.NET\Https:ro
apitwo:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_HTTP_PORTS=8080
- ASPNETCORE_HTTPS_PORTS=8081
ports:
- "8080"
- "8081"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:C:\Users\ContainerUser\AppData\Roaming\Microsoft\UserSecrets:ro
- ${APPDATA}/ASP.NET/Https:C:\Users\ContainerUser\AppData\Roaming\ASP.NET\Https:ro

Похоже, это проблема с сертификатами https. Я просмотрел файловую систему обоих контейнеров в каталог C:\Users\ContainerUser\AppData\Roaming\ASP.NET\Http, а файлы .pfx ApiOne.pfx и ApiTwo.pfx были оба доступен в смонтированном томе в файловых системах обоих контейнеров. Я также могу совершать отдельные вызовы https, когда использую Postman для вызовов https к ApiOne и ApiTwo. Что мне не хватает?

Подробнее здесь: https://stackoverflow.com/questions/791 ... er-compose

Вернуться в «C#»