发布于 2025-02-13 09:53:48 字数 886 浏览 0 评论 0原文

我正在遵循本指南,以在Docker容器中构建我的.NET 6应用程序:

https://stackify.com/a-start-toart-toart-finish-guide-to-docker-for-net/

使用以下dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:6.0 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 80
ENTRYPOINT ["dotnet", "/app/docker-guide.dll"]

我发现这需要很长时间,并且消耗了大量的RAM记忆。

我正在Windows 11上使用Docker桌面。

如何在Docker容器中正确构建它?

I'm following this guide to build my .NET 6 application inside a docker container:

https://stackify.com/a-start-to-finish-guide-to-docker-for-net/

Using the following Dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:6.0 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 80
ENTRYPOINT ["dotnet", "/app/docker-guide.dll"]

I discovered it takes a long time and consumes a huge ammount of RAM memory.

I'm using Docker Desktop at Windows 11.

How can I build it correctly inside a docker container?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲸落 2025-02-20 09:53:49

一段时间后,我发现这与在Dotnet Restore上使用的代理有关。

我在Dotnet还原之前添加:

RUN export http_proxy=proxy:80
RUN export https_proxy=$http_proxy

问题已经解决,现在该建筑物的运作速度更快,并且有合理的RAM。

After some time I found that it has something to do with the proxy being used at dotnet restore.

I added before dotnet restore:

RUN export http_proxy=proxy:80
RUN export https_proxy=$http_proxy

And the problem was solved, now the building is working faster and with a reasonable ammount of RAM.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文