windows - 在 dockerfile 中,如何从 docker 映像中删除目录及其内容?(视窗)
问题描述
我正在使用python:3.6.5-windowsservercore
基本图像。
COPY . /app
将构建上下文复制到C:\app
. 这包括构建项目所需的某些密钥。
运行构建后,我想删除密钥文件夹(C:\app\keys),为此我使用:
RUN powershell.exe Remove-Item -Path C:\app\keys -Force
注意 - 我还尝试了以下每个替代方案:
RUN Remove-Item -Path C:\app\keys -Force
RUN RD /S /Q C:\app\keys
这给了我以下错误:
Step 10/14 : RUN powershell.exe Remove-Item -Path C:\app\keys -Force
---> Running in 4e22124332b1
Remove-Item : Object reference not set to an instance of an object.
At line:1 char:1
+ Remove-Item -Path C:\app\keys -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Remove-Item], NullReferenceEx
ception
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShe
ll.Commands.RemoveItemCommand
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; powershell.exe Remove-Item -Path C:\app\keys -Force' returned a non-zero code: 1
删除图像内目录的方法是什么?
解决方案
解决方案:
RUN Remove-Item -Path C:\app\keys -Force -Recurse
有2个方面可以解决这个问题。
根据您的基本映像,您的默认 shell 是什么?bash 还是 powershell?就我而言,它是 powershell,因此无需在命令开头提及 powershell.exe。
原始命令不正确
RUN Remove-Item -Path C:\app\keys -Force
,因为该文件夹有子文件夹和文件。所以不得不提-Recurse
推荐阅读
- r - ggplot - 将刻度与轴对齐
- java - 意图失败 Android Java
- python - 如何在 Heroku 网站中自动停止计费?
- c - 1941 年的 mktime 或 tz 数据库意外返回
- sql - NOT EXISTS 具有多个条件的表达式
- apache-kafka - 这是在生产中安装 Confluent 模式注册表、kafka 和 zookeeper 的更好方法
- java - Leetcode 有效回文问题问题调试
- xml - 正值仅适用于 XSD 文件中的 double
- powershell - powershell get-winevent 如何只获取路径和exe文件?
- intellij-idea - 在构建命令之前运行 CMD/Powershell 命令?