skip to Main Content

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

2

Answers


  1. 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 . 
    
    Login or Signup to reply.
  2. 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/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search