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

docker login using -p gives error, and when I switch to --password-stdin like it recommends still gives error - gitlab-ci

我的 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 来代替:

我得到这个错误:

"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 runners 并登录到 GitLab Container registry 时有一个更新的权限模型。

作为per the docs,您可以:

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 docs --password-stdin 是一个标志而不是命令行变量。在提供的示例中,密码不是直接通过命令行从文件中读取的。