在 windows 机器上构建 docker 图像时 chmod CommandNotFoundException

chmod CommandNotFoundException when building docker image on windows machine

我们正在尝试在 Windows 10 机器上构建一个 Python-flask 图像,这里是 Dockerfile 中的命令。

RUN chmod +x /var/www/projectname/entrypoint.local.sh

我们在尝试使用 docker 文件构建图像时遇到错误

错误如下:

chmod : The term 'chmod' is not recognized as the name of a cmdlet, function,  script file, or operable program. Check the spelling of the name, or if a path  was included, verify that the path is correct and try again. At line:1 char:76
+ ... nce = 'Stop'; $ProgressPreference = 'SilentlyContinue'; chmod +x /var ...
+                                                             ~~~~~
    + CategoryInfo          : ObjectNotFound: (chmod:String) [], ParentContain     sErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException   ERROR: Service 'controller_service' failed to build: The command 'powershell
-Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; chmod +x /var/www/projectname/entry point.local.sh' returned a non-zero code: 1

正在将 Dockerfile 中的 chmod 视为 Windows 命令。

编辑 1:

我正在尝试使用以下命令构建图像作为 docker-compose 的一部分:

docker-compose up --build.

我是运行上面的命令在TerminalPycharmWindows.

请提出解决此问题的建议。谢谢!

当您实际配置 Docker desktop 以构建 Windows images.

时,您似乎正在尝试构建 Linux 图像

这就是您可能收到错误 chmod command not found 的原因,该错误特定于 Linux,并且在 Windows.

上不起作用

您可以按照以下步骤解决。

  1. 转到任务栏右下角的 Docker 桌面图标。
  2. 右键单击并单击 Switch to Linux containers 选项。
  3. 现在尝试构建图像。

你应该可以开始了。