Use Docker to build Docker images

You can use GitLab CI/CD with Docker to create Docker images. For example, you can create a Docker image of your application, test it, and publish it to a container registry.

To run Docker commands in your CI/CD jobs, you must configure GitLab Runner to support docker commands.

Enable Docker commands in your CI/CD jobs

To enable Docker commands for your CI/CD jobs, you can use:

If you don’t want to execute a runner in privileged mode, but want to use docker build, you can also use kaniko or buildah.

If you are using shared runners on GitLab.com, learn more about how these runners are configured.

Use the shell executor

To include Docker commands in your CI/CD jobs, you can configure your runner to use the shell executor. In this configuration, the gitlab-runner user runs the Docker commands, but needs permission to do so.

  1. Register a runner. Select the shell executor. For example:

    sudo gitlab-runner register -n \
      --url https://gitlab.com/ \
      --registration-token REGISTRATION_TOKEN \
      --executor shell \
      --description "My Runner"
    
  2. On the server where GitLab Runner is installed, install Docker Engine. View a list of .

  3. Add the gitlab-runner user to the docker group:

    sudo usermod -aG docker gitlab-runner
    
  4. Verify that gitlab-runner has access to Docker:

    sudo -u gitlab-runner -H docker info
    
  5. In GitLab, to verify that everything works, add docker info to .gitlab-ci.yml:

    before_script:
      - docker info
    
    build_image:
      script:
        - docker build -t my-docker-image .
        - docker run my-docker-image /script/to/run/tests
    

You can now use docker commands (and install docker-compose if needed).

When you add gitlab-runner to the docker group, you are effectively granting gitlab-runner full root permissions. Learn more about the .

Use Docker-in-Docker

“Docker-in-Docker” (dind) means: