How to Start a Docker Container Inside your GitLab CI Pipeline

Quite often, we use GitLab CI to dockerize our applications. But how to start a Docker container from the GitLab Container Registry? Can we use Docker Compose? A lesser-known feature in GitLab CI is the services keyword which allows you to start one or more Docker images and link them to your job. Let’s explore how this works.

Valentin Despa
DevOps with Valentine

--

Last update: September 2023

Background

Allow me to describe the following scenario for a pipeline. I have built a Node.js application that exposes an API.

So the current pipeline has the following stages:

  • build where all dependencies are installed
  • test where all unit tests and executed
  • package where the application is dockerized, and the image is being pushed to the GitLab Container Registry.

For your reference, this is how the .gitlab-ci.yml looks like this at this stage:

stages:
- build
- test
- package

build:
stage: build
image: node:14-alpine
script:
- npm ci…

--

--

Valentin Despa
DevOps with Valentine

Software developer, educator & overlander • GitLab Hero • AWS Community Builder • Postman Supernova • Imprint: http://vdespa.com/imprint