EDIT (2023): Do not keep using docker-compose! Please migrate to docker compose, which is now part of the docker image and a 99% drop-in replacement of docker-compose. Ironically, if you (now) use docker:latest, the question does not apply. See Docker's documentation on Compose V2. The answer below only applies to docker-compose, AKA Compose V1, which is to be discontinued/become unsupported.


Docker also provides an official docker-compose image: docker/compose

This is the ideal solution if you don't want to install it every pipeline.

Note that in the latest version of GitLab CI/Docker you will likely need to give privileged access to your GitLab CI Runner and configure/disable TLS. See Use docker-in-docker workflow with Docker executor

variables:
  DOCKER_HOST: tcp://docker:2375/
  DOCKER_DRIVER: overlay2

# Official docker compose image.
image:
  name: docker/compose:latest

services:
  - docker:dind

before_script:
  - docker version
  - docker-compose version

build:
  stage: build
  script:
    - docker-compose down
    - docker-compose build
    - docker-compose up tester-image

Note that in versions of docker-compose earlier than 1.25:

Since the image uses docker-compose-entrypoint.sh as entrypoint you'll need to override it back to /bin/sh -c in your .gitlab-ci.yml. Otherwise your pipeline will fail with No such command: sh

    image:
      name: docker/compose:latest
      entrypoint: ["/bin/sh", "-c"]
Answer from webmaster777 on Stack Overflow
Top answer
1 of 11
120

EDIT (2023): Do not keep using docker-compose! Please migrate to docker compose, which is now part of the docker image and a 99% drop-in replacement of docker-compose. Ironically, if you (now) use docker:latest, the question does not apply. See Docker's documentation on Compose V2. The answer below only applies to docker-compose, AKA Compose V1, which is to be discontinued/become unsupported.


Docker also provides an official docker-compose image: docker/compose

This is the ideal solution if you don't want to install it every pipeline.

Note that in the latest version of GitLab CI/Docker you will likely need to give privileged access to your GitLab CI Runner and configure/disable TLS. See Use docker-in-docker workflow with Docker executor

variables:
  DOCKER_HOST: tcp://docker:2375/
  DOCKER_DRIVER: overlay2

# Official docker compose image.
image:
  name: docker/compose:latest

services:
  - docker:dind

before_script:
  - docker version
  - docker-compose version

build:
  stage: build
  script:
    - docker-compose down
    - docker-compose build
    - docker-compose up tester-image

Note that in versions of docker-compose earlier than 1.25:

Since the image uses docker-compose-entrypoint.sh as entrypoint you'll need to override it back to /bin/sh -c in your .gitlab-ci.yml. Otherwise your pipeline will fail with No such command: sh

    image:
      name: docker/compose:latest
      entrypoint: ["/bin/sh", "-c"]
2 of 11
99

Following the official documentation:

# .gitlab-ci.yml
image: docker
services:
  - docker:dind    
build:
  script:
    - apk add --no-cache docker-compose
    - docker-compose up -d

Sample docker-compose.yml:

version: "3.7"
services:
  foo:
    image: alpine
    command: sleep 3
  bar:
    image: alpine
    command: sleep 3

We personally do not follow this flow anymore, because you loose control about the running containers and they might end up running endless. This is because of the docker-in-docker executor. We developed a python-script as a workaround to kill all old containers in our CI, which can be found here. But I do not suggest to start containers like this anymore.

🌐
GitLab
docs.gitlab.com › install › docker › installation
Install GitLab in a Docker container | GitLab Docs
To install GitLab in a Docker container, use Docker Compose, Docker Engine, or Docker Swarm mode.
Discussions

How to use Docker Compose In Gitlab CI
As I have tried to go with:| docker-compose-playgroound: stage: docker-compose-playgroound image: docker:18 services: - docker:18-dind tags: - docker-main variables: DOCKER_TLS_CERTDIR: "" DOCKER_HOST: tcp://docker:2375 script: - docker compose -f .gitlab/docker-compose-autotests.yml up However ... More on forum.gitlab.com
🌐 forum.gitlab.com
0
1
January 2, 2024
Using the .gitlab-ci.yml file to access the docker-compose.yml file
Hello, I would be grateful if someone could clarify something for me. I have two servers: GitLab Server: Repositories GitLab Runner: Runner + Docker On my GitLab server I have created a project with some code. In the root directory of my project, I have placed two files, .gitlab-ci.yml and ... More on forums.docker.com
🌐 forums.docker.com
0
0
April 22, 2024
How to use docker-compose.yml file in GitLab Runner server?
Hello, I would be grateful if someone could clarify something for me. I have two servers: GitLab Server: Repositories GitLab Runner: Runner + Docker On my GitLab server I have created a project with some code. In the root directory of my project, I have placed two files, .gitlab-ci.yml and ... More on forum.gitlab.com
🌐 forum.gitlab.com
0
0
April 22, 2024
Gitlab inside docker
Docker on Mac has a 2GB ram limit by default, you might need to increase that https://docs.docker.com/desktop/settings/mac/#resources More on reddit.com
🌐 r/gitlab
10
2
May 25, 2023
🌐
Medium
medium.com › @BuildWithLal › gitlab-setup-using-docker-compose-a-beginners-guide-3dbf1ef0cbb2
Setup GitLab Using Docker Compose: A Beginner’s Guide | by Lal Zada | Medium
October 10, 2024 - First it will do docker pull gitlab/gitlab-ce if the gitlab/gitlab-ce docker image does not exist on your local machine. After pulling the docker image, it will do docker run gitlab/gitlab-ce · So you can see how docker compose combines 2 separate commands into a single YAML file.
🌐
GitHub
github.com › sameersbn › docker-gitlab › blob › master › docker-compose.yml
docker-gitlab/docker-compose.yml at master · sameersbn/docker-gitlab
Dockerized GitLab. Contribute to sameersbn/docker-gitlab development by creating an account on GitHub.
Author   sameersbn
🌐
DEV Community
dev.to › teetoflame › setting-up-a-gitlab-server-community-edition-and-a-gitlab-runner-using-docker-compose-ob6
Setting Up a GitLab Server (Community Edition) and a GitLab Runner Using Docker Compose - DEV Community
February 20, 2025 - Set up a Docker-based GitLab and a GitLab Runner using Docker Compose to create a CI/CD environment. Services will be defined in the docker-compose.yml file, configuring storage, exposing GitLab on a local port, and registering the GitLab Runner ...
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
How to use Docker Compose In Gitlab CI - GitLab CI/CD - GitLab Forum
January 2, 2024 - As I have tried to go with:| docker-compose-playgroound: stage: docker-compose-playgroound image: docker:18 services: - docker:18-dind tags: - docker-main variables: DOCKER_TLS_CERTDIR: "" DOCKER_HOST: tcp://docker:2375 script: - docker compose -f .gitlab/docker-compose-autotests.yml up However ...
🌐
GeeksforGeeks
geeksforgeeks.org › git › install-gitlab-by-using-docker
Install GitLab By Using Docker - GeeksforGeeks
July 23, 2025 - Here are some useful Docker commands for managing your GitLab instance: ... Ports Already in Use: If ports 80, 443, or 22 are already in use, either free up the ports or modify the port mappings in the docker-compose.yml file.
Find elsewhere
🌐
Cylab
cylab.be › blog › 229 › continuous-deployment-with-gitlab-and-docker-compose
Continuous Deployment with GitLab and docker-compose | cylab.be
September 19, 2023 - This key should remain secret, so we will add the key as an environment variable: on the web interface of GitLab, head to Settings > CI/CD > Variables. There you can add a variable with name SSH_PRIVATE_KEY, and the value is the content of the private SSH key on the deployment server. You can get the content of the private key with: ... Create an other variable with name SSH_HOST_KEY and the value of the fingerprint of the server. Now, in the source code of the project (next to the Dockerfile), we can create a template with name docker-compose.tmpl.
🌐
GitLab
docs.gitlab.com › install › docker › configuration
Configure GitLab running in a Docker container | GitLab Docs
The settings contained in GITLAB_OMNIBUS_CONFIG aren’t written to the gitlab.rb configuration file, and are evaluated on load. To provide multiple settings, separate them with a colon (;). The following example sets the external URL, enables LFS, and starts the container with a minimal shm size required for Prometheus: sudo docker run --detach \ --hostname gitlab.example.com \ --env GITLAB_OMNIBUS_CONFIG="external_url 'http://gitlab.example.com'; gitlab_rails['lfs_enabled'] = true;" \ --publish 443:443 --publish 80:80 --publish 22:22 \ --name gitlab \ --restart always \ --volume $GITLAB_HOME/config:/etc/gitlab \ --volume $GITLAB_HOME/logs:/var/log/gitlab \ --volume $GITLAB_HOME/data:/var/opt/gitlab \ --shm-size 256m \ gitlab/gitlab-ee:<version>-ee.0
🌐
GitHub
github.com › mgcrea › docker-compose-gitlab-ce
GitHub - mgcrea/docker-compose-gitlab-ce: Compose file for Gitlab Community Edition · GitHub
You can quickly start your compose gitlab instance (requires a working automated nginx_proxy compose instance) git clone git@github.com:mgcrea/docker-compose-gitlab-ce.git gitlab; cd $_ cp .env.default .env; nano .env make docker-compose up -d
Starred by 113 users
Forked by 42 users
Languages   Ruby 88.0% | Makefile 9.4% | Shell 2.6%
🌐
Mike Polinowski
mpolinowski.github.io › devops › gitops › install gitlab with docker-compose (debian bullseye)
Install Gitlab with Docker-Compose (Debian Bullseye) | Mike Polinowski
docker-compose up -d docker-compose ps Name Command State Ports ---------------------------------------------------------------------------------------------------------- gitlab-ce /assets/wrapper Up (unhealthy) 0.0.0.0:2222->22/tcp,:::2222->22/tcp, ...
🌐
DevOps in the clouds
czerniga.it › strona główna › how to install gitlab using docker compose?
How to install GitLab using Docker Compose?
September 26, 2022 - For convenience, we will also set an environment variable that will contain the path to our Gitlab directory: ... # docker-compose.yml version: '3.7' services: web: image: 'gitlab/gitlab-ce:latest' restart: always hostname: 'localhost' container_name: gitlab-ce environment: GITLAB_OMNIBUS_CONFIG: | external_url 'http://localhost' ports: - '8080:80' - '8443:443' volumes: - '$GITLAB_HOME/config:/etc/gitlab' - '$GITLAB_HOME/logs:/var/log/gitlab' - '$GITLAB_HOME/data:/var/opt/gitlab' networks: - gitlab gitlab-runner: image: gitlab/gitlab-runner:alpine container_name: gitlab-runner restart: always depends_on: - web volumes: - /var/run/docker.sock:/var/run/docker.sock - '$GITLAB_HOME/gitlab-runner:/etc/gitlab-runner' networks: - gitlab networks: gitlab: name: gitlab-network
🌐
Medium
weng-albert.medium.com › build-gitlab-with-docker-easy-deployment-guide-en-bb1f729f5d57
Build GitLab with Docker: Easy Deployment Guide(En) | by Albert Weng | Medium
March 7, 2024 - You can choose to either directly change the host's SSH port and avoid using 22, or modify GitLab to use a different port than 22. #--------------------------------------------------- # S3-3. create docker-compose.yaml #--------------------------------------------------- [root]# mkdir -p /root/gitlab/ [root]# vim docker-compose.yml version: '3.6' services: gitlab: image: gitlab/gitlab-ce:latest container_name: gitlab restart: always hostname: 'gitlab.test.example.poc' environment: GITLAB_OMNIBUS_CONFIG: | external_url 'http://gitlab.test.example.poc:8929' gitlab_rails['gitlab_shell_ssh_port'] = 2424 ports: - '8929:8929' - '8443:8443' - '2424:2424' volumes: - '$GITLAB_HOME/config:/etc/gitlab' - '$GITLAB_HOME/logs:/var/log/gitlab' - '$GITLAB_HOME/data:/var/opt/gitlab' shm_size: '256m' [root]# docker-compose up -d [root]# docker ps
🌐
GitHub
github.com › hutchgrant › gitlab-docker-local
GitHub - hutchgrant/gitlab-docker-local: Install, configure, and run Gitlab CE and Gitlab-Runner in local docker containers via docker-compose. · GitHub
Install, configure, and run Gitlab CE and Gitlab-Runner in local docker containers via docker-compose. - hutchgrant/gitlab-docker-local
Starred by 30 users
Forked by 14 users
Languages   Shell 73.4% | Dockerfile 26.6%
🌐
Medium
medium.com › @BuildWithLal › dockerized-gitlab-ci-setting-up-and-connecting-your-gitlab-runner-b810a02e42f2
Dockerized GitLab CI: Setting Up and Connecting Your GitLab Runner | by Lal Zada | Medium
October 10, 2024 - In the first post, we set up a GitLab server using barebone docker commands. In the next post, we transitioned those barebone docker commands into a docker compose file for better usability and managing multiple containers easily.
🌐
Cloud Infrastructure Services
cloudinfrastructureservices.co.uk › home › blog › how to setup gitlab docker compose container image
How to Setup GitLab Docker Compose Container Image
February 10, 2023 - Next, create a data directory to store GitLab data. Then, export the data directory with the following command. After that, change the directory to your project and create a docker-compose.yml configuration file for GitLab.
🌐
Atlantic.Net
atlantic.net › home › blog › how to install gitlab with docker and docker compose on arch linux
How to install GitLab with Docker and Docker Compose on Arch Linux
June 2, 2024 - version: '3.7' services: web: image: 'gitlab/gitlab-ce:latest' restart: always hostname: 'localhost' container_name: gitlab-ce environment: GITLAB_OMNIBUS_CONFIG: | external_url 'http://localhost' ports: - '8080:80' - '8443:443' volumes: - '$GITLAB_HOME/config:/etc/gitlab' - '$GITLAB_HOME/logs:/var/log/gitlab' - '$GITLAB_HOME/data:/var/opt/gitlab' networks: - gitlab gitlab-runner: image: gitlab/gitlab-runner:alpine container_name: gitlab-runner restart: always depends_on: - web volumes: - /var/run/docker.sock:/var/run/docker.sock - '$GITLAB_HOME/gitlab-runner:/etc/gitlab-runner' networks: - gitlab networks: gitlab: name: gitlab-network · Save and close the file when you are done. At this point, the docker-compose.yml file is ready to start the GitLab container.
🌐
Docker Community
forums.docker.com › docker engine › compose
Using the .gitlab-ci.yml file to access the docker-compose.yml file - Compose - Docker Community Forums
April 22, 2024 - Hello, I would be grateful if someone could clarify something for me. I have two servers: GitLab Server: Repositories GitLab Runner: Runner + Docker On my GitLab server I have created a project with some code. In the root directory of my project, I have placed two files, .gitlab-ci.yml and ...
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
How to use docker-compose.yml file in GitLab Runner server? - GitLab CI/CD - GitLab Forum
April 22, 2024 - Hello, I would be grateful if someone could clarify something for me. I have two servers: GitLab Server: Repositories GitLab Runner: Runner + Docker On my GitLab server I have created a project with some code. In the root directory of my project, I have placed two files, .gitlab-ci.yml and ...
🌐
ComputingForGeeks
computingforgeeks.com › home › run gitlab in docker containers using docker compose
Run GitLab in Docker Containers using Docker Compose [Guide]
August 19, 2022 - Step-by-step guide to run GitLab in Docker Containers using Docker Compose. Includes commands, verification, and troubleshooting.