Skip to content

Instantly share code, notes, and snippets.

@bkuhl
Last active February 5, 2024 12:08
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bkuhl/3487ec4557eee8de6700d6a0ab058e72 to your computer and use it in GitHub Desktop.
Save bkuhl/3487ec4557eee8de6700d6a0ab058e72 to your computer and use it in GitHub Desktop.
How to use docker-compose in GitLab CI
# Using edge-git ensures we're always pulling the latest
# You can lock into a specific version using the *-git tags
# on https://hub.docker.com/_/docker/
image: docker:edge-git
services:
- docker:dind
# If you only need compose in a specific step definitely put this
# only in that step so it's not executed unnecessarily
before_script:
- apk add --no-cache py2-pip && pip install docker-compose
@markbirbeck
Copy link

Just in case anyone comes here via Google, this can actually be done slightly more easily with the tmaier/docker-compose image:

image: tmaier/docker-compose:latest

services:
  - docker:dind

before_script:
  - docker info
  - docker-compose --version

build image:
  stage: build
  script:
    - docker-compose build

@milesrichardson
Copy link

Thank you. This was way too hard to find.

@league55
Copy link

+1 Thanks

@jasonhildebrand
Copy link

+1 Using an image with docker-compose pre-installed reduced my CI job from 8 minutes to 4.

@edjeordjian
Copy link

Thanks!!

@JohnVonNeumann
Copy link

For reference, in markbirbeck's solution he is using a third party provided image, docker now supports their own compose image which you can use exactly the same if 3rd party deps for containers are worrying to you.

Just replace:
image: tmaier/docker-compose:latest

With:
image: docker/compose:latest

@hermesalvesbr
Copy link

Which executor it's better to build with docker-compose?

Enter an executor: parallels, shell, virtualbox, docker+machine, docker-ssh+machine, custom, docker, kubernetes, docker-ssh, ssh

I tried with docker:latest

image

@Mudasar-Makandar
Copy link

I was getting same issue. This fixed,

  1. Use shell executor
  2. Make sure you have installed docker & docker-compose.
  3. Allow gitlab-runner to access docker with usermod -a -G docker gitlab-runner in your server

Everything should work now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment