Using docker-compose in a GitLab CI pipeline

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

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.