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.

🌐
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.
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
3
1
January 2, 2024
Using docker-compose in a GitLab CI pipeline - Stack Overflow
I'm trying to implement a GitLab continuous integration (CI) pipeline with the following .gitlab-ci.yml file: image: docker:latest # When using dind, it's wise to use the overlayfs driver for # More on stackoverflow.com
🌐 stackoverflow.com
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
How to install GitLab using Docker Compose?
🌐 r/gitlab
1
3
November 15, 2021
🌐
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.
🌐
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
🌐
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.
🌐
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 ...
Find elsewhere
🌐
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.
🌐
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%
🌐
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
🌐
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
🌐
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, ...
🌐
ComputingForGeeks
computingforgeeks.com › home › run gitlab ce in docker with docker compose
Run GitLab in Docker Containers using Docker Compose [Guide]
1 week ago - Tell GitLab about this by adding to GITLAB_OMNIBUS_CONFIG: ... After adding this and running sudo docker compose up -d, the project pages will display the correct SSH clone URL with port 2222.
🌐
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.
🌐
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.
🌐
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.
Top answer
1 of 4
23

The problem

This is complex problem.

The docker:latest image is based on alpine (Alpine Linux), which is built using musl-libc. This system is very barebones, and as such doesn't have everything a full-fledged desktop Linux might have. In fact, dynamic executables need to be compiled specifically for this system.

docker-compose is a Python application, bundled into a Linux executable using PyInstaller. These executables are really only expected to be able to run on the system which they were built. If you run an alpine container, and apk add file, you can see that the (dynamically-linked) executable you downloaded is expecting a specific interpreter.

# file /usr/local/bin/docker-compose
/usr/local/bin/docker-compose.pyinstaller: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=00747fe5bcde089bb4c2f1ba7ab5348bc02ac5bf, stripped

The problem is /lib64/ld-linux-x86-64.so.2 doesn't exist in alpine. In fact, /lib64 doesn't even exist.

The solution

Because docker-compose is a Python application, it can also be installed using pip:

Testing this inside an alpine container:

$ docker run --rm -it alpine /bin/bash

Here are the commands you can run manually, or add to your .gitlab-ci.yml before_script:

# apk add --no-cache python py2-pip
...
# pip install --no-cache-dir docker-compose
...
# docker-compose -v
docker-compose version 1.11.1, build 7c5d5e4

It turns out there is actually an open issue for this:

  • https://github.com/docker/compose/issues/3465
2 of 4
19

Docker-compose is now an official image. You can put

image: 
  name: docker/compose:1.23.2
  entrypoint: [""]

at the top of your .gitlab-ci.yml. You need to remove the default entrypoint of the compose image, which is done by the second line. After that, you can use both docker and docker-compose.

This works per GitLab 9.4. You can also build a custom image

FROM docker/compose:1.23.2
ENTRYPOINT []

and use it as your image.

🌐
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
🌐
Medium
medium.com › @Mondin0 › how-to-set-up-gitlab-community-edition-with-docker-compose-a-step-by-step-guide-a4ad5558ed41
How to Set Up GitLab Community Edition with Docker Compose: A Step-by-Step Guide | by Gabriel Mondino | Medium
October 11, 2025 - Create a docker-compose.yml file with the following content: services: gitlab: image: gitlab/gitlab-ce:latest container_name: gitlab restart: always hostname: 'localhost' environment: GITLAB_OMNIBUS_CONFIG: | external_url 'http://localhost:8929' gitlab_rails['gitlab_shell_ssh_port'] = 2424 nginx['enable'] = true gitlab_rails['registry_enabled'] = true registry_external_url 'http://localhost:5050' ports: - '8929:8929' - '2424:22' - '5050:5050' volumes: - gitlab_config:/etc/gitlab - gitlab_logs:/var/log/gitlab - gitlab_data:/var/opt/gitlab - registry_data:/var/opt/gitlab/gitlab-rails/shared/registry shm_size: '256m' volumes: gitlab_config: gitlab_logs: gitlab_data: registry_data: