1
votes

I'm running a gitlab/gitlab-ce container on docker. Then , inside it, i want to run a gitlab-runner service, by providing docker as runner. And every single command that i run (e.g docker ps, docker container ..), i get this error:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running

P.s: i've tried service docker restart, reinstal docker and gitlab-runner.

2
It seems that your docker daemon isnt started normally (which maybe caused by some errors such as cgroups), maybe you can read the docker daemon's log for trouble shooting~? - firesurfing
Why does your gitlab runner have to be in the same container as GitLab? This kind of goes against Docker practices. What would be better would be to run the runner in a separate container and then network the two containers together. - disflux

2 Answers

2
votes

By default it is not possible to run docker-in-docker (as a security measure).

You can run your Gitlab container in privileged mode, mount the socket (-v /var/run/docker.sock://var/run/docker.sock) and try again.

Also, there is a docker-in-docker image that has been modified for docker-in-docker usage. You can read up on it here and create your own custom gitlab/gitlab-ce image.

In both cases, the end result will be the same as docker-in-docker isn't really docker-in-docker but lets your manage the hosts docker-engine from within a docker container. So just running the Gitlab-ci-runner docker image on the same host has the same result and is a lot easier.

1
votes

By default the docker container running gitlab does not have access to your docker daemon on your host. The docker client uses a socket connection to communicate to the docker daemon. This socket is not available in your container.

You can use a docker volume to make the socket of your host available in the container:

docker run -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-ce

Afterwards you will be able to use the docker client in your container to communicate with the docker daemon on the host.