简体   繁体   English

在Docker上运行.net Core 2.0 Web API时连接被拒绝

[英]Connection refused while running .net core 2.0 web api on docker

These are my beginnings with docker, however I'm stuck now. 这些是我从Docker开始的起点,但是现在我被困住了。

When I run my .NET Core Web Api typing: 当我运行.NET Core Web Api时,键入:

dotnet run

this is my result: 这是我的结果:

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.

And everything works great. 一切都很好。 But after build docker container with this: 但是在构建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"]

result is: 结果是:

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.

but I cannot access to endpoints any longer. 但我无法再访问端点。

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

In general this build is for my ubuntu server, but I have tried it on windows the effect is the same. 通常,此构建适用于我的ubuntu服务器,但是我在Windows上尝试过,效果是相同的。

Any special settings are required? 需要任何特殊设置吗? I read many tutorials and I thought that this should work. 我阅读了许多教程,我认为这应该可行。

I'd be very grateful for any help. 如有任何帮助,我将不胜感激。

You might need to try exposing the port in the container to the outside world. 您可能需要尝试将容器中的端口暴露给外界。 Add the following to your docker-compose file. 将以下内容添加到您的docker-compose文件中。 This will map port 80 to the local host port 80 这会将端口80映射到本地主机端口80

ports:
  -80:80

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM