使用 -p 进行 docker 登录会出现错误,当我像它建议的那样切换到 --password-stdin 时,仍然会出现错误 - gitlab-ci

标签 docker gitlab gitlab-ci gitlab-ci-runner

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

相关文章:

docker-compose 未知主机?

java - Java 11 的 GitLab Auto DevOps 问题

gitlab-ci - 使 kubectl 在 gitlab ci 中工作

Android:找不到或加载主类 org.gradle.wrapper.GradleWrapperMain

webpack - ActionView::Template::Error: 当使用 ci/cd autodevops 部署到 Gitlab 时,Webpacker 无法在/app/public/packs/manifest.json 中找到应用程序

Docker-Compose 挂载卷覆盖主机文件

docker - docker从容器运行python

docker - 在docker中提交正在运行的容器是 "safe"吗?

Git merge 比较 from 到 含义

javascript - 使用 GitLab API 和 Node.js 下载 GitLab 存储库存档