3

I have a working Dockerfile that requires execution with BuildKit support.

Question: how can I build the dockerfile from gitlab-ci and set DOCKER_BUILDKIT=1 globally?

.gitlab-ci.yml:

    image: docker:20
    
    variables:
      DOCKER_DRIVER: overlay2
    
    services:
      - docker:dind

    build:  
      script:
        - docker build . 

Dockerfile:

    FROM maven:3.8.4-eclipse-temurin-11 as dependencies
    COPY pom.xml .
    COPY src src
    RUN --mount=type=cache,target=/root/.m2 mvn package
danielnelz
  • 3,794
  • 4
  • 25
  • 35
membersound
  • 81,582
  • 193
  • 585
  • 1,120

2 Answers2

4

Gitlab runs inside a linux (native or container), so I suggest you to change .gitlab-ci.yml as follow:

image: docker:20

variables:
  DOCKER_DRIVER: overlay2

services:
  - docker:dind

build:  
  script:
    - DOCKER_BUILDKIT=1 docker build . 
Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
4

An other way is to create an environment variable as such:

image: docker:20

variables:
  DOCKER_BUILDKIT: 1

# …

See https://docs.gitlab.com/ee/ci/variables/