我正在尝试让我的.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
,则它可以正常运行。只有当我尝试在注册表中链接我的图像时。
答案 0 :(得分:1)
正如您在评论中所确认的那样,gitlab.com/my/project
是一个私有存储库,因此不能直接将docker pull
或image:
属性与registry.gitlab.com/my/project/test:latest
一起使用。
但是,您应该能够使用.gitlab-ci.yml
并手动运行image: docker:latest
命令(包括docker
)来适应docker login
。
这依赖于所谓的Docker-in-Docker (dind) approach,它是supported by GitLab CI。
这里是
.gitlab-ci.yml
的通用模板,它依赖于此思想:
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
定义并用您自己的Bash脚本替换TODO
区域,只需确保满足两个条件即可:
docker run … "
和"
包围(最后一个变量"$CI_JOB_NAME"
是一个细节,是可选的,只允许覆盖Bash变量$0
中引用的PS4
变量docker run … "$IMAGE" /bin/sh -c "…"
命令本身之前被解析。