How to run docker CLI in the in a Container

Hi All,

I’m trying to run docker CLI in a container and connecting it to the Docker daemon on the host. I have register the gitlab runner to use docker and share /var/run/docker.sock and use the docker image in the .gitlab-ci.yml file. I’m receiving error during the start of the docker build.
time=“2019-12-13T11:31:29Z” 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 no such host” 25 error during connect: Posthttp://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=iewgymdujsnu3tx7z1mer1z3t&shmsize=0& context canceled29 ERROR: Job failed: exit code 1

Thanks for your help


the easiest way would be to use the Docker-in-Docker workflow, where you use the docker image inside your .gitlab-ci.yml and start the dind service.

What’s your use case with passing the socket? Can you share the existing CI config?


Hello @dnsmichi ,

Thanks for the reply, I have tried the docker-in-docker workflow that you are suggesting its working, Now i’m trying this approach bind-mount /var/run/docker.sock into container. I’m using Windows 10 Pro, Docker Toolbox (version 19.03.1) and Gitlab-runner (version:12.5.0) .

These are the CI config I’m running:


image: docker:19.03.1

  - build
  - package
  - deploy

  image: maven:3-jdk-8
  stage: build
  script: "mvn package -B"
      - target/*.jar

  stage: package
  - docker build -t .
  - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN
  - docker push
  stage: deploy
  - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN
  - docker pull
  - docker run --name test -p 9090:8080 -i


concurrent = 1
check_interval = 0

  session_timeout = 1800

  name = "docker runner"
  url = ""
  executor = "docker"
    tls_verify = false
    image = "docker:19.03.1"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
    shm_size = 0

But it seems like build container can not have access to docker sock. Is there any configuration I need to do?


well, Windows fun … there are no unix domain sockets, and after googling a bit, I’ve found this entry. It says that you can access a named pipe instead of the unix socket. Also, it points to the Docker for Windows FAQ

Maybe the following environment variable helps in your .gitlab-ci.yml

  DOCKER_HOST: npipe:////./pipe/docker_engine

If the named pipe approach fails for some reason (could be that docker.exe is not running with it), try the following variable value tcp:// (if that’s exposed in the Docker settings on your Windows client).

If may be the case that you also need to explicitly tell the docker CLI command where to connect to in your script sections if the variable has no effect.