最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

.net - Nuget Bind mounts in Dockerfile - Stack Overflow

programmeradmin3浏览0评论

I currently have a Dockerfile that I'm trying to get working to build a .NET project which uses Paket. A minimal example of it is as follows:

FROM mcr.microsoft/dotnet/sdk:8.0 AS result

# Install Paket etc
# Copy in source code
COPY ./global.json ./paket.dependencies ./paket.lock ./MyProject.sln .
COPY ./.paket/ .paket/

RUN --mount=type=bind,source="c:/Users/User.Name/.nuget/packages",target=/root/.nuget/packages \
     /root/.dotnet/tools/paket restore

With the last step in the Dockerfile, I'm trying to mount the C:\Users\User.Name\.nuget\packages folder so that can be used as a cache, and the packages don't have to be pulled down every time. However, when doing this, Docker complains that it could not compute the checksum of this directory, and that it does not exist. Using a relative path to that folder doesn't work either. Any suggestions would be greatly appreciated.

I currently have a Dockerfile that I'm trying to get working to build a .NET project which uses Paket. A minimal example of it is as follows:

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS result

# Install Paket etc
# Copy in source code
COPY ./global.json ./paket.dependencies ./paket.lock ./MyProject.sln .
COPY ./.paket/ .paket/

RUN --mount=type=bind,source="c:/Users/User.Name/.nuget/packages",target=/root/.nuget/packages \
     /root/.dotnet/tools/paket restore

With the last step in the Dockerfile, I'm trying to mount the C:\Users\User.Name\.nuget\packages folder so that can be used as a cache, and the packages don't have to be pulled down every time. However, when doing this, Docker complains that it could not compute the checksum of this directory, and that it does not exist. Using a relative path to that folder doesn't work either. Any suggestions would be greatly appreciated.

Share Improve this question asked Jan 20 at 1:32 flying_loaf_3flying_loaf_3 4222 gold badges5 silver badges15 bronze badges 2
  • Can you use the native Docker Buildkit caching mechanism; RUN --mount=type=cache,target=... without naming a specific host directory? – David Maze Commented Jan 20 at 2:32
  • Hi David, I did eventually stumble on this solution and gave it a go, but it seemed to produce a different result to just doing the paket restore curiously. I'll specify my steps for how I solved this. – flying_loaf_3 Commented 2 days ago
Add a comment  | 

1 Answer 1

Reset to default 0

What I ended up doing was reading the Paket documentation. I realised that it uses the paket.dependencies and paket.lock file to figure out what dependencies it needs to install.

So in the Dockerfile, I first copied in these two files and then did the paket restore before copying in the rest of the sourcecode and building it. This allows these two layers to be cached, and they don't have to be re-run unless the paket.dependencies or paket.lock changes.

发布评论

评论列表(0)

  1. 暂无评论