我的 gitlab 服务器上有一个 docker 注册表设置。这是我的 .gitlab-ci.yml 文件:
image: docker:18.05.0-ce
services:
- docker:dind
stages:
- build
- test
- release
variables:
TEST_IMAGE: http://my.gitlab.ip:4444/path/to/project:$CI_COMMIT_REF_NAME
RELEASE_IMAGE: http://my.gitlab.ip:4444/path/to/project:latest
before_script:
- docker login -u $USERNAME -p $PASSWORD http://my.gitlab.ip:4444
build:
stage: build
script:
- docker build --pull -t $TEST_IMAGE .
- docker push $TEST_IMAGE
# ...
# more commands
我正在使用 secret 变量作为我的用户名和密码。当我推送代码并且运行程序运行此文件时,出现以下错误:
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://my.gitlab.ip:4444/v2/: http: server gave HTTP response to HTTPS client
所以我尝试使用 --password-stdin
代替,如下所示:
- docker登录-u $用户名--password-stdin $密码http://my.gitlab.ip:4444
我收到此错误:
"docker login" requires at most 1 argument.
See 'docker login --help'.
Usage: docker login [OPTIONS] [SERVER] [flags]
编辑:
我也为我的 docker 登录命令尝试过这个:
docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
并收到此错误:
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://my.gitlab.ip:4444/v2/: http: server gave HTTP response to HTTPS client
我在我的 gitlab 服务器上进行了以下更改:
在/etc/default/docker 中:
DOCKER_OPTS="--insecure-registry http://my.gitlab.ip:4444"
在/etc/docker/daemon.json 中:
{
"insecure-registries" : ["http://my.gitlab.ip:4444"]
}
我也在我的 gitlab runner(不同的服务器)上做了同样的事情。
为什么错误显示我使用的是 https?如何将其更改为 http?
最佳答案
我不确定您何时设置此设置,但在 GitLab 8.12
之后,使用 GitLab 运行程序并登录 GitLab 容器注册表时,有一个更新的权限模型。
如per the docs ,你可以这样做:
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
关于使用 -p 进行 docker 登录会出现错误,当我像它建议的那样切换到 --password-stdin 时,仍然会出现错误 - gitlab-ci,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51211323/