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.
Published in
6 min readNov 2, 2021
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 installedtest
where all unit tests and executedpackage
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…