I have tried to set up a local gitlab-runner in a Docker container on my Ubuntu server so that I can build and push Docker images. I am able to set up and register the runner, but when trying to check the setup with a test repository the CI outputs the following error message when executing the job:
ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I am quite new to this so I do not know what might be the issue.
The server is running Ubuntu 18.04 on which I have installed Docker 19.03.5 and Docker Compose 1.25.0.
I created the following directory for the gitlab-runner:
.
│
└── gitlab
│
├── config.toml
│ │
│ └── config.toml
│
└── docker-compose.yml
docker-compose.yml content:
version: '3'
services:
gitlab-runner:
image: gitlab/gitlab-runner:latest
container_name: gitlab_runner
restart: always
volumes:
- ./config/:/etc/gitlab-runner/
- /var/run/docker.sock:/var/run/docker.sock
I then registered the runner:
docker-compose run --rm gitlab-runner register -n \
--url https://gitlab.com/ \
--registration-token *<token>* \
--executor docker \
--description "My Docker Runner" \
--docker-image "docker:stable" \
--docker-volumes /var/run/docker.sock:/var/run/docker.sock
The config.toml file was the updated like this:
[[runners]]
name = "My Docker Runner"
url = "https://gitlab.com/"
token = "*<token>*"
executor = "docker"
[runners.docker]
tls_verify = false
image = "docker:stable"
privileged = false
disable_cache = false
volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
shm_size = 0
[runners.cache]
I then started the gitlab-runner container:
docker-compose up -d
I created a Dockerfile in GitLab repository just for test:
FROM python:latest
RUN apt-get update
The .gitlab-ci.yml i set up like this:
image: docker:stable
stages:
- build
build:
stage: build
script:
- docker info
- docker build -t docker_python_test .
This is the output from the runner:
1 Running with gitlab-runner 12.5.0 (577f813d)
2 on Docker Runner Test 001 *<token>*
3
ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (executor_docker.go:980:0s)
00:09
4 Will be retried in 3s ...
5 ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (executor_docker.go:980:0s)
6 Will be retried in 3s ...
7 ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (executor_docker.go:980:0s)
8 Will be retried in 3s ...
10 ERROR: Job failed (system failure): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (executor_docker.go:980:0s)