I have configured gitlab runner within kubernetes , which is not able to connect to docker daemon . Showing below error .
$ 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
My config.toml file is as below
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]
Checked with configuration as below
image: docker:19.03.1
services:
- docker:19.03.1-dind
variables:
DOCKER_HOST: tcp://docker:2375
And my .gitlab-ci.yml file after changing the configuration is as below:
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
but getting bellow error :
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
use docker19, which automatically configures its host for you:
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