假设有如下的文件结构:
project root
|-- X.sln
|-- src
| |-- Foo
| | |-- Foo.fsproj
| | |-- Foo.fs
| |-- Bar
| |-- Bar.fsproj
| |-- Bar.fs
|-- test
|-- Baz
|-- Baz.fsproj
我想先将所有的.fsproj
文件添加到我的Docker镜像中,然后运行一个命令,最后再添加其余的文件。我尝试了以下方法,但显然它没有起作用:
COPY X.sln .
COPY **/*.fsproj .
RUN dotnet restore
COPY . .
RUN dotnet build
这个想法是,在前两个 COPY
步骤之后,映像文件系统上的文件树就像这样:
working dir
|-- X.sln
|-- src
| |-- Foo
| | |-- Foo.fsproj
| |-- Bar
| |-- Bar.fsproj
|-- test
|-- Baz
|-- Baz.fsproj
只有在 RUN dotnet restore
之后,树的其余部分才被添加。
有没有一种方法可以模拟这种行为,最好不用求助于 dockerfile 外的脚本?
dotnet restore
命令通常需要相当长的时间,所以在不必要时避免使用它,可以大幅减少构建时间。 - Tomas Aschan