首页 > 解决方案 > docker login using -p 给出错误,当我像它推荐的那样切换到 --password-stdin 时仍然给出错误 - 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 login 命令尝试了这个:

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?

标签: dockergitlabgitlab-cigitlab-ci-runner

解决方案


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

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

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

推荐阅读