【问题标题】:Docker push to Google Cloud Registry -- HTTP request to an HTTPS serverDocker 推送到 Google Cloud Registry——对 HTTPS 服务器的 HTTP 请求
【发布时间】:2020-09-18 08:35:42
【问题描述】:

我的.gitlab-ci.yml 管道似乎无法正常工作。我可以在 gitlab 上构建、测试和重新标记,但部署阶段在尝试将图像推送到 gcr.io 时失败。管道文件和失败消息的相关摘录如下。我尝试了 slim 和 alpine 图像,并通过 echo、export 和 gcloud auth list 确认 GCP_SERVICE_ACCOUNT 变量是我在 gitlab 系统中设置并成功验证的变量。我无法通过谷歌搜索找到任何解决 http 与 https 不一致的问题——只有与我所做的一致的语法,或者用于替代身份验证方法。过去,当我在本地机器上进行身份验证并推送到 gcr.io 时,gcloud push ... 工作得很好。

我还尝试在Push to google container registry fails: Retrying 的每个答案中插入docker-credential-gcr configure-docker --token-source="gcloud" 并使用asia.gcr.io(因为我在澳大利亚)。那篇文章中的问题不一样,但我在这一点上挣扎。

请问我哪里错了?

image: docker:19.03.12

services:
  - docker:19.03.12-dind

stages:
  - build
  - test
  - release
  - deploy

variables:
  GIT_DEPTH: 1
  DOCKER_HOST: tcp://docker:2376
  DOCKER_TLS_CERTDIR: "/certs"
  CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
  CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
  GCR_IO_IMAGE: gcr.io/proj-000000/$CI_REGISTRY_IMAGE:latest

...

deploy:
  image: google/cloud-sdk:slim
  stage: deploy
  only:
  - master
  before_script:
  - echo $GCP_SERVICE_ACCOUNT > /tmp/service_account.json
  - gcloud auth activate-service-account --key-file /tmp/service_account.json
  script:
  - docker push $GCR_IO_IMAGE
  - gcloud app deploy app.yaml --project proj --image-url $GCR_IO_IMAGE

$ docker push $GCR_IO_IMAGE 来自守护程序的错误响应:客户端向 HTTPS 服务器发送了 HTTP 请求。 错误:作业失败:退出代码 1

更新跟随 Frederic G 的以下帖子: gcloud docker ... 方法现在似乎已被弃用,但遵循失败说明中弹出的建议:

deploy:
  image: google/cloud-sdk:alpine
  stage: deploy
  only:
  - master
  script:
  - gcloud auth activate-service-account --key-file /tmp/service_account.json
  - gcloud auth configure-docker
  - docker push $GCR_IO_IMAGE
  - gcloud app deploy sandkastenapp.yaml --project sandkasten --image-url $GCR_IO_IMAGE

现在给出:

$ gcloud auth configure-docker
Adding credentials for all GCR repositories.
WARNING: A long list of credential helpers may cause delays running 'docker build'. We recommend passing the registry name to configure only the registry you are using.
After update, the following will be written to your Docker config file
 located at [/root/.docker/config.json]:
 {
  "credHelpers": {
    "gcr.io": "gcloud",
    "us.gcr.io": "gcloud",
    "eu.gcr.io": "gcloud",
    "asia.gcr.io": "gcloud",
    "staging-k8s.gcr.io": "gcloud",
    "marketplace.gcr.io": "gcloud"
  }
}
Do you want to continue (Y/n)?  
Docker configuration file updated.
$ docker push $GCR_IO_IMAGE
read tcp 172.17.0.4:42954->172.17.0.3:2376: read: connection reset by peer
ERROR: Job failed: exit code 1

【问题讨论】:

    标签: docker gitlab-ci google-container-registry


    【解决方案1】:

    你可以做的是使用gcloud docker 命令来推送图像,如下所示:

    gcloud docker -- push gcr.io/example-org/example-image:latest
    

    或者,在运行 docker 命令之前,我认为您需要通过编写 credential file 来配置它。您需要运行这些命令:

    gcloud docker --authorize-only
    docker push gcr.io/example-org/example-image:latest
    

    -编辑-

    我看到您在 Cloud Build 设置中设置了此变量

    DOCKER_HOST: tcp://docker:2376
    

    这可能会导致问题,因为您收到的错误消息中提到了该端口。

    172.17.0.3:2376: read: connection reset by peer
    

    在进行测试时,当我没有设置该值时,我可以使用以下命令推送图像:

    gcloud auth configure-docker
    docker pull nginx
    docker tag nginx gcr.io/[project]/website
    docker push gcr.io/[project]/website
    

    【讨论】:

    • 这感觉像是进步——gcloud docker 方法现在似乎已被弃用,但它传递的错误消息将我引导至我添加到原始帖子的更新。
    猜你喜欢
    • 1970-01-01
    • 2016-07-06
    • 1970-01-01
    • 1970-01-01
    • 2020-07-15
    • 1970-01-01
    • 2017-11-09
    • 2020-04-23
    • 2020-05-03
    相关资源
    最近更新 更多