我试图让我的.gitlab-ci.yml
文件使用来自 Gitlab 容器注册表的图像。我已成功上传Dockerfile
到注册表,我可以从本地机器上的注册表中提取图像并构建一个容器就好了。但是,当我的 .gitlab-ci.yml
使用该图像时文件,我得到这个错误:
Authenticating with credentials from job payload (GitLab Registry)
standard_init_linux.go:190: exec user process caused "no such file or directory"
我看过一堆关于 Windows EOL 字符的讨论,但我正在运行
Raspbian
我不相信这是这里的问题。但是,我对此很陌生,无法弄清楚问题所在。我很感激任何帮助。.gitlab-ci.yml
文件:before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
stages:
- test-version
test:
stage: test-version
image: registry.gitlab.com/my/project/test:latest
script:
- python --version
test.Dockerfile
(在注册表中为 registry.gitlab.com/my/project/test:latest
):ARG base_img="python:3.6"
FROM ${base_img}
# Install Python packages
RUN pip install --upgrade pip
编辑:
另外需要注意的是,如果我更改
.gitlab-ci.yml
中的图像文件到 python:3.6
,然后它运行得很好。只有当我尝试在注册表中链接我的图像时。
最佳答案
正如您在评论中确认的那样,gitlab.com/my/project
是私有(private)仓库,所以不能直接使用docker pull
或 image:
registry.gitlab.com/my/project/test:latest
的属性(property).
但是,您应该能够调整您的 .gitlab-ci.yml
通过使用 image: docker:latest
并手动运行 docker
命令(包括 docker login
)。
这依赖于所谓的Docker-in-Docker (dind) approach , 它是 supported by GitLab CI .
Here is a generic template of
.gitlab-ci.yml
relying on this idea:
stages:
- test-version
test:
stage: test-version
image: docker:latest
services:
- docker:dind
variables:
# GIT_STRATEGY: none # uncomment if "git clone" is unneeded
IMAGE: "registry.gitlab.com/my/project/test:latest"
before_script:
# - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
# or better
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY"
script:
- docker pull "$IMAGE"
- |
docker run --rm -v "$PWD:/build" -w /build "$IMAGE" /bin/bash -c "
export PS4='+ \e[33;1m(\$0 @ line \$LINENO) \$\e[0m ' # optional
set -ex # mandatory
## TODO insert your multi-line shell script here ##
echo \"One comment\" # quotes must be escaped here
: A better comment
python --version
echo $PWD # interpolated outside the container
echo \$PWD # interpolated inside the container
## (cont'd) ##
" "$CI_JOB_NAME"
- echo done
这会导致更多样板,但这是通用的,因此您只需替换
IMAGE
定义并替换TODO
使用您自己的 Bash 脚本的区域,只需确保满足这两项:docker run … "
包围。和 "
(最后一个变量 "$CI_JOB_NAME"
是一个细节,它是可选的,只允许覆盖 Bash 变量 $0
中引用的 PS4
变量)docker run … "$IMAGE" /bin/sh -c "…"
之前被解析。命令自己。 关于docker - 由于 "no such file or directory"导致 gitlab CI 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59671156/