在docker上运行.net core 2.0 web api时连接被拒绝

时间:2018-03-20 22:22:12

标签: .net ubuntu docker

这是我与码头工作的开始,但我现在已经陷入困境。

当我运行.NET Core Web Api时输入:

dotnet run

这是我的结果:

Hosting environment: Production
Content root path: C:\Users\...\PickCashOut.API\PickCashOut.Web
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.

一切都很好。但是用这个构建docker容器之后:

FROM microsoft/dotnet:2.0-sdk as builder
ENV DOTNET_CLI_TELEMETRY_OPTOUT 1
WORKDIR /app

COPY . ./
RUN dotnet restore PickCashOut.Web/PickCashOut.Web.csproj
RUN dotnet publish PickCashOut.Web/PickCashOut.Web.csproj -c Release -o out -r linux-x64

FROM microsoft/dotnet:2.0-runtime
ENV ASPNETCORE_URLS http://+:80
WORKDIR /app
COPY --from=builder /app/PickCashOut.Web/out .
ENTRYPOINT ["dotnet", "PickCashOut.Web.dll"]

结果是:

Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {25360c91-217e-4770-962a-6282970c245c} may be persisted to storage in unencrypted form.
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.

但我再也无法访问端点了。

Failed to connect to 195.*.*.87 port 80: Connection refused

一般来说,这个版本适用于我的ubuntu服务器,但是我在windows上试过它的效果是一样的。

是否需要任何特殊设置?我阅读了很多教程,我认为这应该有效。

我非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您可能需要尝试将容器中的端口暴露给外部世界。将以下内容添加到docker-compose文件中。这会将端口80映射到本地主机端口80

ports:
  -80:80