gpt4 book ai didi

Docker 构建失败 - 带有 GKE 的 Gitlab CI。无法通过 tcp ://localhost:2375. 连接到 Docker 守护进程 docker 守护进程是否正在运行?

转载 作者:行者123 更新时间:2023-12-02 12:05:49 24 4
gpt4 key购买 nike

我将 Google Kubernetes Engine 与我的 Gitlab 存储库集成,并从 gitlab 创建了一个集群。
现在我正在尝试使用 gitlab-ci 构建我的 docker 镜像。并将其推送到 Google Container Registry。
但我不断收到此错误:

Running with gitlab-runner 11.2.0 (35e8515d)
on gitlab runner vm instance 4e6e33ed
Using Docker executor with image docker:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image sha256:edbe3f3ad406799b528fe6633c5553725860566b638cdc252e0520010436869f for docker:dind ...
Waiting for services to be up and running...

*** WARNING: Service runner-4e6e33ed-project-8016623-concurrent-0-docker-0 probably didn't start properly.

Health check error:
ContainerStart: Error response from daemon: Cannot link to a non running container: /runner-4e6e33ed-project-8016623-concurrent-0-docker-0 AS /runner-4e6e33ed-project-8016623-concurrent-0-docker-0-wait-for-service/service (executor_docker.go:1305:0s)

Service container logs:
2018-11-14T13:02:37.917684152Z mount: permission denied (are you root?)
2018-11-14T13:02:37.917743944Z Could not mount /sys/kernel/security.
2018-11-14T13:02:37.917747902Z AppArmor detection and --privileged mode might break.
2018-11-14T13:02:37.917750733Z mount: permission denied (are you root?)

*********

Pulling docker image docker:latest ...
Using docker image sha256:062267097b77e3ecf374b437e93fefe2bbb2897da989f930e4750752ddfc822a for docker:latest ...
Running on runner-4e6e33ed-project-8016623-concurrent-0 via gitlab-runners..

###
# Running before_script commands here
###

# Error Comes on Docker build command
Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?
ERROR: Job failed: exit code 1

这是我的 gitlab-ci.yml。
services:
- docker:dind

before_script:
- apk update && apk upgrade && apk add --no-cache bash openssh

variables:
DOCKER_DRIVER: overlay2

stages:
- build

build:
stage: build
image: docker:latest
variables:
DOCKER_HOST: tcp://localhost:2375
before_script:
# Pre-requisites required to install google cloud sdk on gitlab runner
- export COMMIT_SHA=$(echo $CI_COMMIT_SHA | cut -c1-8)
- apk update
- apk upgrade
- apk add --update ca-certificates
- apk add --update -t deps curl
- apk del --purge deps
- rm /var/cache/apk/*
script:
# Build our image using docker
- docker build -t $GCP_PROJECT_ID/$CI_PROJECT_NAME:$COMMIT_SHA .

# Write our GCP service account private key into a file
- echo $GCLOUD_SERVICE_KEY | base64 -d > ${HOME}/gcloud-service-key.json

# Download and install Google Cloud SDK
- wget https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz
- tar zxvf google-cloud-sdk.tar.gz && ./google-cloud-sdk/install.sh --usage-reporting=false --path-update=true

# Update gcloud components
- google-cloud-sdk/bin/gcloud --quiet components update

# Give access to gcloud project
- google-cloud-sdk/bin/gcloud auth activate-service-account --key-file ${HOME}/gcloud-service-key.json || die "unable to authenticate service account for gcloud"

# Get current projects credentials to access it
- google-cloud-sdk/bin/gcloud container clusters get-credentials gitlab-kube --zone cluster-zone --project project-id

# Configure container registry to push using docker
- docker login -u _json_key --password-stdin https://gcr.io < ${HOME}/gcloud-service-key.json

# Push the image using docker
- docker push $GCP_PROJECT_ID/$CI_PROJECT_NAME:$COMMIT_SHA

docker 镜像是在本地构建的。
我还在各种帖子上看到更新 config.toml文件,但我的项目中没有。在哪里添加该文件?

谢谢

最佳答案

首先:你不需要gcloud将您的图像推送到 GCP。通过服务帐户进行身份验证(就像您一样)就足够了。 (见:https://cloud.google.com/container-registry/docs/advanced-authentication#json_key_file)

但是...如果您真的想使用 Gloud SDK,请使用 google/gcloud-sdk图像而不是 docker工作中的图像(Docker 已经存在于 google/gcloud-sdk 图像中)

接下来,要使用 docker 守护程序,您需要指定好的端点。您使用 docker:dind服务所以,Docker 主机将是 tcp://docker:2375/ ( docker 是您的服务的主机名)

最后,您的运行者将需要“特权”模式(执行 DIND)。 (见:https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker-executor)

这是一个简单的示例(抱歉,未经测试),可以做到这一点:

stages:
- build

build:
stage: build
image: google/cloud-sdk
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375/
before-script:
- echo $GCLOUD_SERVICE_KEY | base64 -d > ${HOME}/gcloud-service-key.json
script:
- docker build -t $GCP_PROJECT_ID/$CI_PROJECT_NAME:$COMMIT_SHA .
- docker login -u _json_key --password-stdin https://gcr.io < ${HOME}/gcloud-service-key.json
- docker push $GCP_PROJECT_ID/$CI_PROJECT_NAME:$COMMIT_SHA

关于Docker 构建失败 - 带有 GKE 的 Gitlab CI。无法通过 tcp ://localhost:2375. 连接到 Docker 守护进程 docker 守护进程是否正在运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53301514/

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