我在docker-compose中有两个容器。 1-Api 2-网络 Webcliet无法直接向Api发送请求。Web必须在端口80801 https上运行,而Api必须在端口8080 http上运行。
当我使用https:// localhost:80801 /打开Web时,它将进行调试,直到使用以下地址通过Web调用Api:http:// Api:8080或http:// localhost:8080,但我拒绝连接。
我也无法使用https:// web:80801 /和http:// Api:8080打开网站。它给了我DNS错误。
docker-compose.override.yml
ToIntFunction
用于网络的Dockerfile
version: '3.4'
services:
Api:
container_name: Api
image: Api
container_name: Api
hostname: Api
domainname: Api.test
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "8080:8080"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
web:
container_name: web
image: web
container_name: web
hostname: web
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:80801;http://+:80
- ASPNETCORE_HTTPS_PORT=80801
ports:
- "80801:80801"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
links:
- Api
用于网络的dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80801
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["web/web.csproj", "web/"]
COPY ["ShopVieweModel/ShopVieweModel.csproj", "ShopVieweModel/"]
COPY ["WebFrameWork/WebFrameWork.csproj", "WebFrameWork/"]
COPY ["Common/Common.csproj", "Common/"]
COPY ["Shop.Data/Shop.Data.csproj", "Shop.Data/"]
COPY ["Shop.Entities/Shop.Entities.csproj", "Shop.Entities/"]
COPY ["Shop.Core/Shop.Core.csproj", "Shop.Core/"]
COPY ["Api/Api.csproj", "Api/"]
COPY ["Shop.Ioc/Shop.Ioc.csproj", "Shop.Ioc/"]
COPY ["ApiTest/ApiTest.csproj", "ApiTest/"]
RUN dotnet restore "web/web.csproj"
COPY . .
WORKDIR "/src/web"
RUN dotnet build "web.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "web.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "web.dll"]
这是docker ps结果
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Api/Api.csproj", "Api/"]
COPY ["Shop.Entities/Shop.Entities.csproj", "Shop.Entities/"]
COPY ["ShopVieweModel/ShopVieweModel.csproj", "ShopVieweModel/"]
COPY ["Shop.Ioc/Shop.Ioc.csproj", "Shop.Ioc/"]
COPY ["Shop.Core/Shop.Core.csproj", "Shop.Core/"]
COPY ["Common/Common.csproj", "Common/"]
COPY ["Shop.Data/Shop.Data.csproj", "Shop.Data/"]
COPY ["WebFrameWork/WebFrameWork.csproj", "WebFrameWork/"]
RUN dotnet restore "Api/Api.csproj"
COPY . .
WORKDIR "/src/Api"
RUN dotnet build "Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Api.dll"]
我的配置有什么问题?
答案 0 :(得分:0)
使用链接或创建网络。 这应该可以帮助您: https://docs.docker.com/compose/networking/
答案 1 :(得分:0)
为此添加了api容器
environment: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_URLS=http://+:61947
现在正在工作。