Docker Desktop MultiContainer无法正常工作'连接被拒绝'

时间:2019-09-28 09:49:05

标签: docker containers

我刚接触docker并遇到了一个愚蠢的问题。

我在已安装并正在运行的Mac上安装了最新的docker桌面。

我已经在Microsoft应用程序上尝试过多容器应用程序

https://docs.microsoft.com/en-us/visualstudio/mac/docker-multi-container?view=vsmac-2019

但是尝试运行它时,始终出现“拒绝连接”错误

阅读其他答案,我的docker-compose.yml问题被驳回

version: '3.4'

services:
  dockerdemofrontend:
    image: ${DOCKER_REGISTRY-}dockerdemofrontend
    build:
      context: .
      dockerfile: DockerDemoFrontEnd/Dockerfile

  dockerdemoapi:
    image: ${DOCKER_REGISTRY-}dockerdemoapi
    build:
      context: .
      dockerfile: DockerDemoAPI/Dockerfile

我的DockerDemoAPI Dockerfile

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY DockerDemoAPI/DockerDemoAPI.csproj DockerDemoAPI/
RUN dotnet restore "DockerDemoAPI/DockerDemoAPI.csproj"
COPY . .
WORKDIR "/src/DockerDemoAPI"
RUN dotnet build "DockerDemoAPI.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "DockerDemoAPI.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DockerDemoAPI.dll"]

我的DockerDemoFrontEnd DockerFile

WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY DockerDemoFrontEnd/DockerDemoFrontEnd.csproj DockerDemoFrontEnd/
RUN dotnet restore "DockerDemoFrontEnd/DockerDemoFrontEnd.csproj"
COPY . .
WORKDIR "/src/DockerDemoFrontEnd"
RUN dotnet build "DockerDemoFrontEnd.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "DockerDemoFrontEnd.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DockerDemoFrontEnd.dll"]

在我的前端项目中 如果我删除http调用并运行项目

var request = new System.Net.Http.HttpRequestMessage();
request.RequestUri = new Uri("http://DockerDemoApi/api/values/1");
var response = await client.SendAsync(request);
ViewData["Message"] += " and " + await response.Content.ReadAsStringAsync();

它运行正常,可以在safari中加载,我可以查看页面。 如果将HTTP重新放回

HttpRequestException: Connection refused

我迷失了解决此问题的方法

谢谢

0 个答案:

没有答案