gpt4 book ai didi

docker - gitlab kubernetes runner 无法连接到 docker 守护进程

转载 作者:行者123 更新时间:2023-12-02 11:35:17 28 4
gpt4 key购买 nike

我在 kubernetes 中配置了 gitlab runner,它无法连接到 docker daemon。显示以下错误。

$ docker build --cache-from "${DOCKER_IMAGE_TAG}" -t "${DOCKER_IMAGE_TAG}" .

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? ERROR: Job failed: command terminated with exit code 1

stages:
- push_to_docker

docker_image:
image: 'docker:latest'
services:
- docker:dind
stage: push_to_docker
variables:
DOCKER_IMAGE_TAG: 'gcr.io/abcd-project/test'
script:
- docker build --cache-from "${DOCKER_IMAGE_TAG}" -t "${DOCKER_IMAGE_TAG}" .
- echo "$SERVICE_ACCOUNT_KEY" > key.json
- docker login -u _json_key --password-stdin https://gcr.io < key.json
- docker push ${DOCKER_IMAGE_TAG}
only:
- master
tags:
- abcd

我的config.toml文件如下

listen_address = "[::]:9252"
concurrent = 4
check_interval = 3
log_level = "info"

[session_server]
session_timeout = 1800

[[runners]]
name = "runner-gitlab-runner-78c7db94bc-lzv76"
request_concurrency = 1
url = "https://gitlab.com/"
token = "*********"
executor = "kubernetes"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.kubernetes]
host = ""
bearer_token_overwrite_allowed = false
image = "ubuntu:16.04"
namespace = "gitlab-managed-apps"
namespace_overwrite_allowed = ""
privileged = true
service_account_overwrite_allowed = ""
pod_annotations_overwrite_allowed = ""
[runners.kubernetes.pod_security_context]
[runners.kubernetes.volumes]

检查配置如下

    image: docker:19.03.1
services:
- docker:19.03.1-dind
variables:
DOCKER_HOST: tcp://docker:2375

更改配置后我的 .gitlab-ci.yml 文件如下:

stages:
- push_to_docker
- deploy_into_kubernetes
variables:
DOCKER_IMAGE_TAG: 'gcr.io/abcd-project/test:$CI_COMMIT_SHORT_SHA'
DOCKER_HOST: tcp://docker:2375

docker_image_creation:
image: docker:19.03.1
services:
- docker:19.03.1-dind

stage: push_to_docker

script:
- docker build -t "${DOCKER_IMAGE_TAG}" .
- echo "$SERVICE_ACCOUNT_KEY" > key.json
- docker login -u _json_key --password-stdin https://gcr.io < key.json
- docker push ${DOCKER_IMAGE_TAG}
tags:
- cluster
- kubernetes

但出现以下错误:

Skipping Git submodules setup $ docker build -t "${DOCKER_IMAGE_TAG}" . time="2019-11-04T08:07:37Z" level=error msg="failed to dial gRPC: cannot connect to the Docker daemon. Is 'docker daemon' running on this host?: dial tcp: lookup docker on 10.0.0.10:53: no such host" error during connect: Post http://docker:2375/v1.40/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=l1ce41pzm1p9a4jdhs31z9p64&shmsize=0&t=gcr.io%2Fupbeat-flame-247110%2Fgitlab-runner-poc%3A25b1faa0&target=&ulimits=null&version=1: context canceled

最佳答案

使用 docker19,它会自动为您配置主机:

image: docker:19.03.1
services:
- docker:19.03.1-dind
variables:
DOCKER_HOST: tcp://docker:2375

https://docs.gitlab.com/ee/ci/docker/using_docker_build.html

关于docker - gitlab kubernetes runner 无法连接到 docker 守护进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58670831/

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