"ERR_CONNECTION_REFUSED"使用Docker的Angular和dotnet核心WebApi [英] "ERR_CONNECTION_REFUSED" Angular and dotnet core WebApi using Docker

查看:91
本文介绍了"ERR_CONNECTION_REFUSED"使用Docker的Angular和dotnet核心WebApi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对Angular/WebApi应用程序进行docker化,并在社区的帮助下,我终于设法构建了一个映像,并且能够在控制台中无错误地执行该映像.但是我无法使用localhost导航到我的应用程序.

I am trying to dockerize my Angular/WebApi application and with help from the community I have finally managed to build an image and being able to execute the image without errors in the console. But I am not able to navigate to my application using localhost.

我的Dockerfile看起来像这样:

My Dockerfile looks like this:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2.105 AS build
WORKDIR /src

# Copy csproj and restore as distinct layers
COPY ["Fightplan_v1/Fightplan_v1.csproj", "Fightplan_v1/"]
COPY ["Fightplan_v1.Autogenerate/Fightplan_v1.Autogenerate.csproj", "Fightplan_v1.Autogenerate/"]
COPY ["Fightplan_v1.Autogenerate.Test/Fightplan_v1.Autogenerate.Test.csproj", "Fightplan_v1.Autogenerate.Test/"]
COPY ["Fightplan_v1.Database/Fightplan_v1.Database.csproj", "Fightplan_v1.Database/"]
COPY ["Fightplan_v1.Helpers/Fightplan_v1.Helpers.csproj", "Fightplan_v1.Helpers/"]
COPY ["Fightplan_v1.Jobs/ConvertImagestoBlob/Fightplan_v1.ConvertImagestoBlob.csproj", "Fightplan_v1.Jobs/ConvertImagestoBlob/"]
COPY ["Fightplan_v1.Models/Fightplan_v1.Models.csproj", "Fightplan_v1.Models/"]
COPY ["Fightplan_v1.Shared/Fightplan_v1.Shared.csproj", "Fightplan_v1.Shared/"]
RUN dotnet restore "Fightplan_v1/Fightplan_v1.csproj"

# Setup NodeJs
RUN apt-get update && \
    apt-get install -y wget && \
    apt-get install -y gnupg2 && \
    wget -qO- https://deb.nodesource.com/setup_10.x | bash - && \
    apt-get install -y build-essential nodejs

# Copy everything else and build
COPY . .
WORKDIR "/src/Fightplan_v1"
RUN dotnet build "Fightplan_v1.csproj" -c Release -o /app/build

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

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
WORKDIR /app
COPY --from=publish /app/publish .

EXPOSE 80
ENTRYPOINT ["dotnet", "Fightplan_v1.dll"]

运行 docker build -f.\ fp.dockerfile -t test 创建一个没有任何错误的映像.运行 docker run -p 5100:80 -it test 可以启动映像,并且在控制台中没有任何错误:,但会给出 XmlKeyManager 警告:

Running docker build -f .\fp.dockerfile -t test . creates an image without any errors. Running docker run -p 5100:80 -it test starts the image without any errors in the console: but it gives an XmlKeyManager warning:

当我尝试转到 http://localhost:5100 时,我在浏览器中得到一个 ERR_CONNECTION_REFUSED ,控制台显示了以下错误:

When I try to go to http://localhost:5100 I get a ERR_CONNECTION_REFUSED in the browser and the console gives me this error:

我试图直接转到 172.17.0.1 ,而不是 localhost .我也尝试过使用 https 代替 http ,但这并没有给我上述 unauthorized 错误,这意味着点击 http 是正确的,但未呈现Angular应用程序.

I have tried to go directly to 172.17.0.1 instead of localhost. I have also tried to use https instead of http but that didn't give me the unauthorized error as above which should mean that hitting http is correct but the Angular application is not rendered.

一切都在本地运行而无需docker.我可以通过Powershell中的 dotnet 命令发布应用程序: dotnet restore dotnet publish .这将使应用程序在 https://localhost:5000 上运行.

Everything works locally without docker. I am able to publish the application via dotnet commands in powershell: dotnet restore and dotnet publish. This will make the application run on https://localhost:5000.

我在Dockerfile中错过了下一步吗?

Am I missing another step in the Dockerfile?

推荐答案

这虽然很隐蔽,但完全是我自己的错.我在 Startup.cs 中有一个 app.UseHttpsRedirection().我删除了它,一切正常.

This was quite hidden but completely my own fault. I had a app.UseHttpsRedirection() in Startup.cs. I removed this and everything worked.

这篇关于"ERR_CONNECTION_REFUSED"使用Docker的Angular和dotnet核心WebApi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆