【发布时间】:2019-12-12 10:20:11
【问题描述】:
我正在尝试使用 dotnet api 创建一个容器,但是在构建并使用 docker run 命令之后,它无法访问。我需要了解错误发生在哪里才能修复它。
我的一些发行版是 Ubuntu,使用 docker 版本 18.09.5 并使用图像创建 Dockerfile:
microsoft/dotnet:2.2-sdk-alpine microsoft/dotnet:2.2-aspnetcore-runtime-alpine
dockerfile 内容:
FROM microsoft/dotnet:2.2-sdk-alpine AS build-env
WORKDIR /app
ENV ASPNETCORE_URLS http://0.0.0.0:5000
COPY source/*.csproj ./
RUN dotnet restore
COPY source/ ./
RUN dotnet publish -c Release -o out
FROM microsoft/dotnet:2.2-aspnetcore-runtime-alpine
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 5000
ENTRYPOINT ["dotnet", "devops-test.dll", "--urls", "http://0.0.0.0:5000"]
构建命令:
docker build -t freitas/apidotnet .
运行应用的突击队:
docker run -it -p 5000:5000 freitas/apidotnet
运行后,显示此消息:
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {09e12a74-3a22-4ff3-b882-3f546d91d02a} may be persisted to storage in unencrypted form.
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Address not available'.
Hosting environment: Production
Content root path: /app
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
但是,我尝试访问浏览器 http://localhost:5000 或使用邮递员获取 api,但没有响应。
我不知道这个。抱歉我的英语不好,感谢您的帮助。
【问题讨论】:
-
你确定这台机器上没有其他东西在使用5000端口吗?
-
是的。我使用 netstat 进行了检查。仅在启动容器时使用。
-
错误提到了 IPv6,所以也许您需要使用兼容的 URL?
http://::1:5000怎么样 -
我也看到了,但在下一行,它似乎正在侦听 localhost 并且应用程序已启动。我尝试了任何方法,但不起作用:/
标签: api docker asp.net-core .net-core dockerfile