在Docker镜像中运行Team City构建步骤时出错: “ENOENT: no such file or directory, lstat ‘C:\ContainerMappedDirectories'”

66次阅读
没有评论

问题描述

在运行一个Team City构建时,在Docker镜像(stefanscherer/node-windows:8.11.2-nanoserver)中运行了一个命令行步骤。这个步骤非常简单,只是执行了以下命令:

npm install

请注意,Team City允许您指定要在其中运行步骤的Docker镜像;或者,您可以将构建步骤设置为运行以下命令:

docker versiondocker run --rm -w "C:\build" -v "%%CD%%:C:\build" --entrypoint cmd  stefanscherer/node-windows:8.11.2-nanoserver "/c" "npm install"

无论我如何运行这个步骤,我都会收到以下错误:

[09:24:11]npm info it worked if it ends with ok
[09:24:11]npm info using npm@5.6.0
[09:24:11]npm info using node@v8.11.2
[09:24:11]npm info ok 
[09:24:12]npm info it worked if it ends with ok
[09:24:12]npm info using npm@5.6.0
[09:24:12]npm info using node@v8.11.2
[09:24:13]npm ERR! path C:\ContainerMappedDirectories
[09:24:13]npm ERR! code ENOENT
[09:24:13]npm ERR! errno -4058
[09:24:13]npm ERR! syscall lstat
[09:24:13]npm ERR! enoent ENOENT: no such file or directory, lstat 'C:\ContainerMappedDirectories'
[09:24:13]npm ERR! enoent This is related to npm not being able to find a file.
[09:24:13]npm ERR! enoent 
[09:24:13][09:24:13]npm ERR! A complete log of this run can be found in:
[09:24:13]npm ERR!     C:\Users\ContainerAdministrator\AppData\Roaming\npm-cache\_logs\2018-08-14T14_24_13_376Z-debug.log
[09:24:14]Process exited with code -4058
[09:24:14]Process exited with code -4058
[09:24:14]Step Command Line failed

请注意错误信息中的”ENOENT: no such file or directory, lstat ‘C:\ContainerMappedDirectories'”。我在这篇文章中找到了类似的问题:https://github.com/nodejs/node/issues/8897,但是那篇文章似乎暗示这个问题与正在运行的npm版本有关,并且通过更新npm版本可以解决。然而,我可以在我的开发PC上使用完全相同的Docker镜像而没有任何问题。
开发PC信息如下:

Windows 10 Enterprise, version 1803, build 17134.165
PS C:\Users\schaefke> docker version
Client:
 Version:           18.06.0-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        0ffa825
 Built:             Wed Jul 18 19:05:28 2018
 OS/Arch:           windows/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.0-ce
  API version:      1.38 (minimum version 1.24)
  Go version:       go1.10.3
  Git commit:       0ffa825
  Built:            Wed Jul 18 19:23:19 2018
  OS/Arch:          windows/amd64
  Experimental:     false

Team City构建信息如下:

Windows Server 2016
Client:
 Version:      18.03.1-ee-2
 API version:  1.37
 Go version:   go1.10.2
 Git commit:   ebbcd7e
 Built:        Tue Jul 10 21:32:32 2018
 OS/Arch:      windows/amd64
 Experimental: false

Server:
 Engine:
  Version:      18.03.1-ee-2
  API version:  1.37 (minimum version 1.24)
  Go version:   go1.10.2
  Git commit:   ebbcd7e
  Built:        Tue Jul 10 21:49:06 2018
  OS/Arch:      windows/amd64
  Experimental: false

Team City版本:

Version 2017.2.1 build 50732

NPM/Node版本:

npm info using npm@5.6.0
npm info using node@v8.11.2

如果我卸载Docker for Windows 18并安装17,我在本地也会遇到相同的错误。这可能是企业版与社区版之间的问题吗?我不认为这是我使用的Docker镜像的问题,因为它在我的开发机器上运行得很好,也不认为这是与镜像中运行的npm版本有关的问题,原因同上。有人知道可能导致我遇到的问题的原因吗(或者可能是哪个组件,比如Docker镜像、npm、Team City的某个部分或docker本身)?

解决方案

请注意以下操作注意版本差异及修改前做好备份。

方案1

根据您提供的信息,问题可能与Docker镜像中的文件路径有关。您可以尝试在Docker镜像中创建所需的目录,以解决此问题。以下是一种可能的解决方案:
1. 在Dockerfile中添加以下命令,以在构建镜像时创建所需的目录:
RUN mkdir C:\ContainerMappedDirectories
2. 重新构建Docker镜像并运行您的Team City构建步骤。

方案2

如果方案1不起作用,您可以尝试在Team City构建步骤中使用绝对路径来解决此问题。以下是一种可能的解决方案:
1. 修改您的Team City构建步骤,将npm install命令更改为使用绝对路径:
docker run --rm -w "C:\build" -v "%%CD%%:C:\build" --entrypoint cmd stefanscherer/node-windows:8.11.2-nanoserver "/c" "C:\Program Files\nodejs\npm.cmd install"
请注意,这里假设npm命令位于C:\Program Files\nodejs目录中。如果您的安装路径不同,请相应地修改命令。

请尝试上述解决方案,并检查是否解决了您遇到的问题。如果问题仍然存在,请提供更多详细信息,以便我们能够更好地帮助您解决问题。

正文完