在 dind 中从 armhf/ubuntu 构建时回显到 docker 文件中的文件失败
echo to file in docker file fails when building from armhf/ubuntu in dind
我在 Gitlab 上使用 CI 管道来构建 docker 图像以部署到 Raspbian。由于我的构建需要访问一些私有 NPM 包,我在 Docker 文件中包含以下行,它使用存储在环境变量 $NPM_TOKEN:
中的值创建一个令牌文件
RUN echo //registry.npmjs.org/:_authToken=$NPM_TOKEN > ~/.npmrc
从我常用的图像 (resin/raspberrypi3-node
) 构建时,这工作正常。然而,我的一个容器是从 armhf/ubuntu
构建的。执行上述行时,构建失败并出现以下错误:
standard_init_linux.go:207: exec user process caused "no such file or directory"
The command '/bin/sh -c echo //registry.npmjs.org/:_authToken=$NPM_TOKEN >> ~/.npmrc' returned a non-zero code: 1
构建在我的开发机器(Windows 10)上从 docker build
运行良好,但不在 gitlab 管道中。
我已经尝试将我的 docker 和管道文件剥离到最低限度,并从路径中删除了环境变量和波浪号,这对于 ubuntu 仍然失败(但不是树脂)图像。
Dockerfile.test.ubuntu:
FROM armhf/ubuntu
RUN echo hello > world.txt
Dockerfile.test.resin:
FROM resin/raspberrypi3-node
RUN echo hello > world.txt
gitlab-ci.yml:
build_image:
image: docker:git
services:
- docker:dind
script:
- docker build -f Dockerfile.test.resin . # Succeeds
- docker build -f Dockerfile.test.ubuntu . # Fails
only:
- master
我已经搜索过类似的问题,并且在 运行 一个包含 CRLF
组合的 .sh
文件时看到了这个错误报告。虽然我在 Windows 上开发,但我的 IDE (VS Code) 设置为使用 LF
,而不是 CRLF
,并且我已经检查了上述所有文件的合规性。
作为 ,尝试使用 double-quotes 作为您的 echo 参数:
RUN echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
首先,在您的 Dockerfile 中,执行 RUN ls -alrth ~/
检查目标文件夹的 accessibility/presence。
this thread (without any answer), with an example where the final version of the Dockerfile, as seen here, use this .gitlab-ci.yml
中也报告了该错误。
OP bighairdave在评论中确认:
I copied the following from the example @VonC gave, and it worked:
variables:
DOCKER_HOST: "tcp://docker:2375"
DOCKER_DRIVER: overlay2
before_script:
- docker run --rm --privileged hypriot/qemu-register
我在 Gitlab 上使用 CI 管道来构建 docker 图像以部署到 Raspbian。由于我的构建需要访问一些私有 NPM 包,我在 Docker 文件中包含以下行,它使用存储在环境变量 $NPM_TOKEN:
中的值创建一个令牌文件RUN echo //registry.npmjs.org/:_authToken=$NPM_TOKEN > ~/.npmrc
从我常用的图像 (resin/raspberrypi3-node
) 构建时,这工作正常。然而,我的一个容器是从 armhf/ubuntu
构建的。执行上述行时,构建失败并出现以下错误:
standard_init_linux.go:207: exec user process caused "no such file or directory"
The command '/bin/sh -c echo //registry.npmjs.org/:_authToken=$NPM_TOKEN >> ~/.npmrc' returned a non-zero code: 1
构建在我的开发机器(Windows 10)上从 docker build
运行良好,但不在 gitlab 管道中。
我已经尝试将我的 docker 和管道文件剥离到最低限度,并从路径中删除了环境变量和波浪号,这对于 ubuntu 仍然失败(但不是树脂)图像。
Dockerfile.test.ubuntu:
FROM armhf/ubuntu
RUN echo hello > world.txt
Dockerfile.test.resin:
FROM resin/raspberrypi3-node
RUN echo hello > world.txt
gitlab-ci.yml:
build_image:
image: docker:git
services:
- docker:dind
script:
- docker build -f Dockerfile.test.resin . # Succeeds
- docker build -f Dockerfile.test.ubuntu . # Fails
only:
- master
我已经搜索过类似的问题,并且在 运行 一个包含 CRLF
组合的 .sh
文件时看到了这个错误报告。虽然我在 Windows 上开发,但我的 IDE (VS Code) 设置为使用 LF
,而不是 CRLF
,并且我已经检查了上述所有文件的合规性。
作为
RUN echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
首先,在您的 Dockerfile 中,执行 RUN ls -alrth ~/
检查目标文件夹的 accessibility/presence。
this thread (without any answer), with an example where the final version of the Dockerfile, as seen here, use this .gitlab-ci.yml
中也报告了该错误。
OP bighairdave在评论中确认:
I copied the following from the example @VonC gave, and it worked:
variables:
DOCKER_HOST: "tcp://docker:2375"
DOCKER_DRIVER: overlay2
before_script:
- docker run --rm --privileged hypriot/qemu-register