使用 -p 的 docker 登录会出错,当我切换到 --password-stdin 时,它建议仍然会出现错误 - g



我的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

我正在使用一个秘密变量作为我的用户名和密码。当我推送代码并且运行器运行此文件时,出现以下错误:

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

  • 码头工人登录 -u $USERNAME --密码-stdin $PASSWORD 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 运行器(不同的服务器(上做了同样的事情。

为什么它显示我在错误中使用了https以及如何将其更改为http?

我不确定您何时设置此设置,但是在使用 GitLab 运行器并登录到 GitLab 容器注册表时,GitLab 8.12后有一个更新的权限模型。

根据文档,您可以执行以下操作:

before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY

不确定您是否已经解决了问题,但是在搜索登录选项(和最佳实践(的差异时,我注意到您的错误实际上甚至与此无关,是吗?

我们看到的错误如下:

Error response from daemon: Get https://my.gitlab.ip:4444/v2/: http: server gave HTTP response to HTTPS client

但是在您的 .gitlab-ci.yml 文件中,您将https://my.gitlab.ip:4444/v2/列为您的 URL。虽然这不一定是相关的,但在我看来,ssl 在某处缺失,例如 http 与 https。

根据 gitlab 文档 --password-stdin 是一个标志而不是命令行变量。在示例中,密码是从文件中读取的,而不是直接通过命令行读取的。

最新更新