How to install docker in gitlab-ci-runner?

I am using a java:8 image to build a gradle project in I want to install docker in the runner also to build a docker image out of the gradle built artifacts. The command I am using in .gitlab-ci.yml is as follows

- curl -sSL | sh
- newgrp docker
- docker info

Now at “docker info” the build is failing with the below error

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

So how do I install docker in a java:8 image? Or is there any gitlab ci image with java8 and docker built-in?

You are stepping into docker-in-docker space:

Also Google Docker-in-Docker

Thanks for the reply. But can you elaborate how do I configure the runner? I am running the CI in’s shared runner.

I dont think this is possible on the sharer runners, you should set up an private runner since I dont believe they would allow socket mounting on the shared service.

I made it work and here is the .gitlab-ci.yml for reference

image: docker:latest

  - docker:dind

  DOCKER_DRIVER: overlay

  - build
  - package

  image: java:8
  stage: build
    - ./gradlew build
      - build/*

  stage: package
    - cd build
    - docker build -t $IMAGE_NAME .
    - docker login -u $DOCKER_USER -p $DOCKER_PASS
    - docker push $IMAGE_NAME

Cool, good to know.