Using docker in docker with GitLab CI

I’m trying to build docker image using docker in docker (image: docker) container image. My build is failing due to problem with accessing docker socket (Cannot connect to the Docker daemon. Is the docker daemon running on this host?). Here is a simple gitlab-ci.yml file to illustrate the issue:

image: docker

stages:

  • build

build_job:
stage: build
script:
- docker build -t myimage:0.1 .

I’ve found a solution. Here is a proper .gitlab-ci.yml file:

image: docker:latest

services:
- docker:dind

before_script:
- docker info

stages:
  - build

build_job:
  stage: build
  script:
    - docker build -t myimage:0.1 .
1 Like