如何使用Dockerfile复制单个文件?

发布于 2025-01-24 16:24:39 字数 813 浏览 0 评论 0原文

我正在尝试使用dockerfile来构建ASP.NET核心项目。我需要使用多个软件包来还原项目。因此,我将包裹定义为nuget.config文件。

使用Docker,我想将nuget.config文件复制到我的工作目录,以便dotnet Restore命令可以使用它来还原。

这是我的dockerfile看起来

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

# Copy and build
COPY ./src /app
COPY ./NuGet.config /app
RUN dotnet restore /app/Project.Web --configfile ./app/NuGet.config
RUN dotnet publish /app/Project.Web -c Release -o ./build/release --framework net6.0 --no-restore

不幸的是,此行上的以上脚本错误copy ./nuget.config/app

=>错误[build-env 4/6]复制./nuget.config/app 无法计算缓存键:“/nuget.config”:找不到:找不到

如何正确将nuget.config文件正确复制到我的工作目录中?

I am trying to build an ASP.NET Core project using Dockerfile. I need to use multiple package-sources to restore the project. so I defined the package-sources into a NuGet.config file.

Using docker, I want to copy the NuGet.config file to my working directory so that the dotnet restore command can use it to restore from.

Here is how my Dockerfile look like

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

# Copy and build
COPY ./src /app
COPY ./NuGet.config /app
RUN dotnet restore /app/Project.Web --configfile ./app/NuGet.config
RUN dotnet publish /app/Project.Web -c Release -o ./build/release --framework net6.0 --no-restore

Unfortunately, the above script errors on this line COPY ./NuGet.config /app

=> ERROR [build-env 4/6] COPY ./NuGet.config /app
failed to compute cache key: "/NuGet.config" not found: not found

How can I correctly copy the NuGet.config file over to my working directory?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文