如何在Dockerfile中使用循环?
我有一个dockerfile,其4倍相同的说明,只有文件名更改:
COPY ./MyProject.Common/MyProject.Common.csproj /app/MyProject.Common/
RUN dotnet restore /app/MyProject.Common/MyProject.Common.csproj
COPY ./MyProject.Manual/MyProject.Manual.csproj /app/MyProject.Manual/
RUN dotnet restore /app/MyProject.Manual/MyProject.Manual.csproj
COPY ./MyProject.Widgets/MyProject.Widgets.csproj /app/MyProject.Widgets/
RUN dotnet restore /app/MyProject.Widgets/MyProject.Widgets.csproj
COPY ./${CLIENT_PROJECT}/${CLIENT_PROJECT}.csproj /app/${CLIENT_PROJECT}/
RUN dotnet restore /app/${CLIENT_PROJECT}/${CLIENT_PROJECT}.csproj
是否可以使用for loop,以复制
and run 仅一次?类似:
FOR [MyProject.Common, MyProject.Manual, ${CLIENT_PROJECT}]
COPY ./${FOR_PARAM}/${FOR_PARAM}.csproj /app/${FOR_PARAM}/
RUN dotnet restore /app/${FOR_PARAM}/${FOR_PARAM}.csproj
ENDFOR
谢谢! :)
I have a Dockerfile with 4 times the same instructions, only the file name changes:
COPY ./MyProject.Common/MyProject.Common.csproj /app/MyProject.Common/
RUN dotnet restore /app/MyProject.Common/MyProject.Common.csproj
COPY ./MyProject.Manual/MyProject.Manual.csproj /app/MyProject.Manual/
RUN dotnet restore /app/MyProject.Manual/MyProject.Manual.csproj
COPY ./MyProject.Widgets/MyProject.Widgets.csproj /app/MyProject.Widgets/
RUN dotnet restore /app/MyProject.Widgets/MyProject.Widgets.csproj
COPY ./${CLIENT_PROJECT}/${CLIENT_PROJECT}.csproj /app/${CLIENT_PROJECT}/
RUN dotnet restore /app/${CLIENT_PROJECT}/${CLIENT_PROJECT}.csproj
Is it possible to use a for loop, to have COPY
and RUN
only once ? something like:
FOR [MyProject.Common, MyProject.Manual, ${CLIENT_PROJECT}]
COPY ./${FOR_PARAM}/${FOR_PARAM}.csproj /app/${FOR_PARAM}/
RUN dotnet restore /app/${FOR_PARAM}/${FOR_PARAM}.csproj
ENDFOR
Thank you ! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
docker文件中没有
for/loop
指令,因此我建议您:复制
指令,该指令将所有排列为不同的子文件夹中的文件复制。复制
一个外壳脚本,该脚本通过子文件夹编译它们。运行
指令。问候。
There are no
FOR/LOOP
instructions in docker file, so I suggest you to:COPY
instruction which copies all the files arranged into distinct subfolders.COPY
a shell script which loops through subfolder compiling them.RUN
instruction for the above script.Regards.