gpt4 book ai didi

docker - Docker推送到Google Cloud Registry-对HTTPS服务器的HTTP请求

转载 作者:行者123 更新时间:2023-12-02 19:45:07 26 4
gpt4 key购买 nike

我似乎无法使.gitlab-ci.yml管道正常工作。我可以在gitlab上进行构建,测试和重新标记,但是在尝试将镜像推送到gcr.io时,部署阶段失败。下面是管道文件和失败消息的相关摘录。我尝试了细长图像和 Alpine 图像,并通过回显,导出和gcloud auth list确认GCP_SERVICE_ACCOUNT变量是我在gitlab系统中设置并成功通过身份验证的变量。我无法通过谷歌搜索找到解决http与https不对齐的任何内容-只能使用与我所做的操作一致的语法或其他身份验证方法。过去,当我在本地计算机上进行身份验证并推送到gcr.io时,gcloud push ...可以正常工作。
我还尝试插入docker-credential-gcr configure-docker --token-source="gcloud"并根据Push to google container registry fails: Retrying的答案使用asia.gcr.io(因为我在AUS中)。那篇文章中的问题是不一样的,但是我在这一点上遇到了麻烦。
请问我怎么了?

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_IMAGEError response from daemon: Client sent an HTTP request to an HTTPS server.ERROR: Job failed: exit code 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

最佳答案

您可以做的是使用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
-EDIT-
我看到您在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

关于docker - Docker推送到Google Cloud Registry-对HTTPS服务器的HTTP请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63952155/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com