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

Shell runner fails to docker execute after docker run

Describe your question in as much detail as possible:
I’m running my pipeline using shell runner on self-managed Gitlab:

Version:      16.1.0
Git revision: 865283c5
Git branch:   16-1-stable
GO version:   go1.19.9
Built:        2023-06-21T19:14:49+0000
OS/Arch:      linux/amd64

OS Ubuntu 22.04

Linux gr-beta 5.15.0-69-generic #76-Ubuntu SMP Fri Mar 17 17:19:29 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

memory:

free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi       542Mi       6.5Gi       1.0Mi       8.5Gi        14Gi
Swap:          2.0Gi       9.0Mi       2.0Gi

I’m trying to run docker image and after container is up and running I’m trying to execute command on that container using docker exec.
I’m getting:

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

And this is the issue.
I’ve tried a bunch of stuff including:

  • give permissions to socket
  • enable and restart docker
  • etc.

What is strange that if I move that docker exec command to a next dependent job and execute it on the same runner then it works fine.
It’s also works fine if I ssh into runner host and execute it manually by root or by gitlab-runner user.

++ docker run -u 0 --rm -t -d -v /var/run/docker.sock:/var/run/docker.sock -v /root/.docker/config.json:/root/.docker/config.json -v /home/gitlab-runner/builds/Pz8rqmkw/0/pgpro-sdm/shaman/shaman-645802:/app/workdir --env SHAMAN_WORKDIR=/app/workdir --env SHAMAN_SDM_REPO=/app/workdir/src/shardman --env SHAMAN_SDMU_REPO=/app/workdir/src/shardman-utils --env SHAMAN_TESTS=functests/test/access --env SHAMAN_BASE64_PRIVATE_KEY=[MASKED] --name un645802 --privileged registry.l.postgrespro.ru/pgpro-sdm/shaman:go-a05f02e5
30c57d20dc317e67478954bdd8edca727b6aa11bae57650ddfe83e0ea5de2d76
++ echo '$ echo "UNIQ_NAME=$UNIQ_NAME" >> $CI_PROJECT_DIR/build-$CI_PIPELINE_ID.env'
$ echo "UNIQ_NAME=$UNIQ_NAME" >> $CI_PROJECT_DIR/build-$CI_PIPELINE_ID.env
++ echo UNIQ_NAME=un645802
++ echo '$ docker exec -t $UNIQ_NAME bash -c "docker info"'
$ docker exec -t $UNIQ_NAME bash -c "docker info"
++ docker exec -t un645802 bash -c 'docker info'
Client:
 Context:    default
 Debug Mode: false
Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Hi there,

Sorry, I might be misunderstanding but… This command:

docker exec -t un645802 bash -c 'docker info'

is executing “docker info” inside of the container, not on the VM. So, unless your container is a docker container and having docker:dind container next to it (and properly configured so they can talk), this won’t work, because obviously you don’t have docker installed inside a container.

So… we have a bit too less context here, so maybe clarifying what you want to achieve and sharing your .gitlab-ci.yml file would be helpful for community to help you.