🌐
GitLab
forum.gitlab.com › gitlab ci/cd
Example GitLab Runner docker compose configuration - GitLab CI/CD - GitLab Forum
March 26, 2022 - After having spent some time the other day to redo my (“standalone”) runner setup, I figured that I would share this for the benefit of the community. .env: RUNNER_NAME=RUNNER-NAME REGISTRATION_TOKEN=TOKEN CI_SERVER_URL=https://gitlab.com/ docker-compose.yml: version: "3.5" services: dind: image: docker:20-dind restart: always privileged: true environment: DOCKER_TLS_CERTDIR: "" command: - --storage-driver=overlay2 runner: restart: always image:...
🌐
GitLab
docs.gitlab.com › runner › install › docker
Run GitLab Runner in a container | GitLab Docs
To use your local system for the configuration volume and other resources mounted into the gitlab-runner container: Optional. In MacOS systems, /srv does not exist by default. Create /private/srv, or another private directory, for setup. ... docker run -d --name gitlab-runner --restart always \ -v /srv/gitlab-runner/config:/etc/gitlab-runner \ -v /var/run/docker.sock:/var/run/docker.sock \ gitlab/gitlab-runner:latest
Discussions

How to connect a gitlab-runner with a gitlab service via docker-compose?
Describe your question in as much detail as possible: I have the following docker-compose file: version: "3.8" services: gitlab: image: gitlab/gitlab-ce:16.2.3-ce.0 container_name: gitlab hostname: 'gitlab' environment: GITLAB_OMNIBUS_CONFIG: | external_url 'http://gitlab' ports: - '80:80' ... More on forum.gitlab.com
🌐 forum.gitlab.com
0
0
August 11, 2023
How to use Docker Compose In Gitlab CI
What are valid way to run docker compose inside a 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: - ... More on forum.gitlab.com
🌐 forum.gitlab.com
0
1
January 2, 2024
Gitlab Runner can execute jobs with specified docker-compose files in series, but not concurrently (Solved, it totally can)
The question: We’re trying to become more modern with our CI/CD, and as part of that, I’ve recently re-worked the testing for one of our applications to use docker compose; It’s a ruby app with a test suite that takes about 15 minutes to run, and sometimes if Selenium is having a sleepy ... More on forum.gitlab.com
🌐 forum.gitlab.com
0
0
November 10, 2023
Use gitlab-runner with docker-compose
Why would your docker-compose.yml not be in the repo?! At the same time, I don’t know if having the gitlab runner launch services in this way is a great idea. You’re mixing deployment and build. More on reddit.com
🌐 r/gitlab
4
1
April 14, 2020
🌐
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 ...
🌐
GitHub
gist.github.com › benoitpetit › cbe19cdd369ec8c1e0defd245d91751f
complete Gitlab installation and a runner with docker · GitHub
Thanks! :-) I found an auto register version for the runner for inspiration of your work and this combined might be helpful for those passing by: https://gitlab.com/TyIsI/gitlab-runner-docker-compose/-/blob/main/docker-compose.yml?ref_type=heads
🌐
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 ...
🌐
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 - We are setting network_mode to host for the GitLab runner container which will put the GitLab runner container on the host machine’s network so GitLab server can communicate with it through localhost instead of using its container name (container ID can change everytime we recreate containers). After updating the docker-compose.yml file, hit CTRL+C to stop the running container and then run
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
How to connect a gitlab-runner with a gitlab service via docker-compose? - GitLab CI/CD - GitLab Forum
August 11, 2023 - Describe your question in as much detail as possible: I have the following docker-compose file: version: "3.8" services: gitlab: image: gitlab/gitlab-ce:16.2.3-ce.0 container_name: gitlab hostname: 'gitlab' environment: GITLAB_OMNIBUS_CONFIG: | external_url 'http://gitlab' ports: - '80:80' ...
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
How to use Docker Compose In Gitlab CI - GitLab CI/CD - GitLab Forum
January 2, 2024 - What are valid way to run docker compose inside a 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 it has resulted in error: $ docker compose -f .gitlab/docker-compose-autotes...
Find elsewhere
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
Gitlab Runner can execute jobs with specified docker-compose files in series, but not concurrently (Solved, it totally can) - GitLab CI/CD - GitLab Forum
November 10, 2023 - The question: We’re trying to become more modern with our CI/CD, and as part of that, I’ve recently re-worked the testing for one of our applications to use docker compose; It’s a ruby app with a test suite that takes about 15 minutes to run, and sometimes if Selenium is having a sleepy ...
🌐
TestDriven.io
testdriven.io › blog › gitlab-ci-docker
Deploying Self-Hosted GitLab CI Runners with Docker | TestDriven.io
October 29, 2021 - $ docker-compose exec gitlab-runner-container \ gitlab-runner register \ --non-interactive \ --url <YOUR-GITLAB-URL> \ --registration-token <YOUR-GITLAB-REGISTRATION-TOKEN> \ --executor docker \ --description "Sample Runner 1" \ --docker-image "docker:stable" \ --docker-volumes /var/run/docker.sock:/var/run/docker.sock
🌐
Reddit
reddit.com › r/gitlab › use gitlab-runner with docker-compose
r/gitlab on Reddit: Use gitlab-runner with docker-compose
April 14, 2020 -

I’ve just started using gitlab runners, and I’m stuck in a point related to running docker-compose.

I don’t know if my approach ie correct, but I have a docker-compose file that runs multiple docker images on my system, and I want the gitlab runner to pull the code and run the docker-compose.yml file on the host once I push my changes to the repo.

The docker-compose.yml file is not included in the repo. I think that might be the problem, if it is, is there anyway to make the runner use the host’s docker-compose that is already running?

Thank you in advance.

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.

🌐
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 template will be used during the gitlab-ci pipeline to create the deployment docker-compose.yaml · Finally, we can create the .gitlab-ci.yaml. The first stage of the pipeline is to build and save the docker image: # # .gitlab-ci.yaml # https://cylab.be/blog/229/continuous-deployment-with-gitlab-and-docker # stages: - build - deploy build: stage: build ## Run on a gitlab-runner that is configured with docker-in-docker tags: - dind image: docker:20.10.16 services: - docker:20.10.16-dind variables: DOCKER_TLS_CERTDIR: "/certs" before_script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY script: - docker pull $CI_REGISTRY_IMAGE:latest || true - docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE:latest .
🌐
Docker Hub
hub.docker.com › r › sameersbn › gitlab-ci-multi-runner
sameersbn/gitlab-ci-multi-runner - Docker Image
docker run --name gitlab-ci-multi-runner -d --restart=always \ --volume /srv/docker/gitlab-runner:/home/gitlab_ci_multi_runner/data \ --env='CI_SERVER_URL=http://git.example.com/ci' --env='RUNNER_TOKEN=xxxxxxxxx' \ --env='RUNNER_DESCRIPTION=myrunner' --env='RUNNER_EXECUTOR=shell' \ sameersbn/gitlab-ci-multi-runner:1.1.4-7 Copy · Alternatively, you can use the sample docker-compose.yml⁠ file to start the container using Docker Compose⁠
🌐
DEV Community
dev.to › boiledsteak › how-to-set-up-on-prem-gitlab-vcs-gitlab-cicd-gitlab-runner-with-docker-3b5c
How to set up on-prem Gitlab VCS, Gitlab CI/CD, Gitlab Runner, with Docker - DEV Community
November 15, 2023 - Next, in a separate directory, create another docker-compose.yml · version: '3.6' services: gitlab-runner: container_name: gitlab-runner restart: always stdin_open: true tty: true command: register volumes: - '/srv/gitlab-runner/config:/etc/gitlab-runner' - '/var/run/docker.sock:/var/run/docker.sock' image: 'gitlab/gitlab-runner:latest' ports: - '81:80' - '8094:8093'
🌐
Docker Hub
hub.docker.com › r › gitlab › gitlab-runner
gitlab/gitlab-runner - Docker Image
gitlab/gitlab-runner:latest is image that can be used to run GitLab Runner in 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 ...
🌐
GitHub
github.com › flavienbwk › gitlab-runner-docker-compose
GitHub - flavienbwk/gitlab-runner-docker-compose: Gitlab runners easily explained and dockerized with compose.
You can tag jobs and runners so only runners with the specific tags of the job will run your pipeline · To tag a specific job, go to your gitlab-ci.yml file and edit the tags attribute of your job.
Starred by 4 users
Forked by 4 users
Languages   Shell 100.0% | Shell 100.0%