skip to Main Content

I am using gitlab and need to build a docker image within the container image. Every-time I am trying to do that I am getting error :
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Below is my dockerfile which is used as the base image on which I am trying to run my docker build and other docker commands.

FROM somedeveloper/dind-aws-cli:latest
RUN apk add wget
RUN wget https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && 
    mv jq-linux64 /usr/local/bin/jq && 
    chmod +x /usr/local/bin/jq
RUN aws --version 
    && jq --version
VOLUME /var/run/docker.sock

I have also tried the official docker image with dind but that also did not work.
Based on what I could find online everyone seems to be suggesting to mount volume with the socket to run the docker daemon but that does not seem to be working

Not sure what am I missing here. Any guidance would be much appreciated!

2

Answers


  1. Chosen as BEST ANSWER

    Found the solution to my problem. Solution was to define DOCKER_HOST variable for my gitlab pipeline and the configuration looked like this

      image: docker:latest
      services:
        - name: docker:dind
          entrypoint: ["env", "-u", "DOCKER_HOST"]
          command: ["dockerd-entrypoint.sh"]
      variables:
        DOCKER_HOST: tcp://docker:2375/
        DOCKER_DRIVER: overlay2
        DOCKER_TLS_CERTDIR: ""
    

    thanks @larsks for the initial guidance


  2. If your goal is simply to run docker-in-docker (dind), your best bet is the official Docker image (docker:dind), which you can run like this:

    docker run -d --privileged --name dind docker:dind
    

    That will works on systems with either cgroupsv1 or v2, and it provides the current version of Docker (20.10.15 as of this writing).


    The image you’re using appears to be at least three years old, which is ancient for Docker.

    The image has Docker 18.06.3-ce, which won’t work under the current version of many distributions because it only works with cgroups v1, while distributions are in the process of moving to cgroups v2.

    Additionally, this line isn’t doing you any good:

    VOLUME /var/run/docker.sock
    

    That mounts an anonymous Docker volume at /var/run/docker.sock, so you end up with an empty directory. The Docker daemon expects to create a Unix socket at that location; with a directory there it will fail to start.

    If you remove that line from your Dockerfile, then you can successfully start your image — on a system with cgroupsv1 — like this:

    docker run -d --privileged --name dind my-dind-image
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search