I started a docker container gitlab-ci-runner, and then register a runner using docker as executor, using node:latest as docker images. But when i push commit to gitlab,I got this error:
Running with gitlab-runner 11.3.1 (0aa5179e)
on docker-ci 0f9fe2c4
Using Docker executor with image node:latest ...
ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (executor_docker.go:1150:0s)
Here is my gitlab config.toml:
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "docker-ci"
url = "http://gitlab.xxxxxx.com/"
token = "0......fc5"
executor = "docker"
[runners.docker]
tls_verify = false
image = "node:latest"
privileged = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
I start the container using:
sudo docker run -d --name gitlab-runner --restart always \
-v ~/srv/gitlab-runner/config:/etc/gitlab-runner \
-v ~/var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
and register using:
sudo docker run --rm -t -i -v ~/srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register
I'm new to docker, can't find the error reason.Is there someone who can help me?
As your CLI container or gitlab-ci-runner container
need to mount the host machine's Docker socket in the container. This will allow your container to use the host machine's Docker daemon to run containers and build images.
You just need to modified run command of gitlab-ci-runner.
docker run -d --name gitlab-runner --restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest