Course contentsShow
← Cloud and Infrastructure
Lesson 1733 of 2,98936. GitLab CI/CDFree lesson

Docker Executor and Images

Use Docker images as job environments, specify image versions, and understand the default Docker executor.

Docker Executor and Images

You'll learn how to configure job environments using Docker images and the Docker executor in GitLab CI/CD.

The Core Concept

In GitLab CI/CD, your jobs need an environment to run in. The Docker executor runs each job inside a fresh Docker container, giving you a clean, isolated workspace every time. You specify which Docker image to use, and GitLab spins up a container from that image to execute your job's scripts.

Think of it like this: instead of running your build on a messy shared machine where previous builds might have left files behind, you get a brand-new, pre-configured apartment (container) for each job, furnished exactly as you need it (the image).

How It Works

In your .gitlab-ci.yml, you can specify an image at the job level or globally:

# Global image for all jobs
image: node:18

build_job:
  script:
    - npm install
    - npm run build

test_job:
  image: python:3.11  # Override for this specific job
  script:
    - pip install pytest
    - pytest

The image keyword tells GitLab which Docker image to pull from a registry (usually Docker Hub by default). The version tag (:18, :3.11) ensures you get a specific, reproducible environment rather than an unpredictable "latest" version.

The Docker executor is typically the default executor on GitLab.com and most installations because it's lightweight, fast, and provides excellent isolation between jobs.

Image Sources

You can use official images (node:18), custom images from Docker Hub (myorg/custom-build:v2), or private registry images with authentication.

Key Takeaway: The Docker executor runs jobs in isolated containers defined by Docker images, giving you reproducible, clean environments specified by image name and version tag.