I have a .gitlab-ci.yml
file which contains following:
image: docker:latest
services:
- docker:dind
before_script:
- docker info
- docker-compose --version
buildJob:
stage: build
tags:
- docker
script:
- docker-compose build
But in ci-log
I receive message:
$ docker-compose --version
/bin/sh: eval: line 46: docker-compose: not found
What am I doing wrong?
If you don't want to provide a custom docker image with docker-compose preinstalled, you can get it working by installing Python during build time. With Python installed you can finally install docker-compose ready for spinning up your containers.
Use docker-compose exec with -T if you receive this or a similar error:
EDIT I added another answer providing a minimal example for a .gitlab-ci.yml configuration supporting docker-compose.
docker-compose
can be installed as a Python package, which is not shipped with your image. The image you chose does not even provide an installation of Python:Looking for Python gives an empty result. So you have to choose a different image, which fits to your needs and ideally has docker-compose installed or you maually create one.
The docker image you chose uses Alpine Linux. You can use it as a base for your own image or try a different one first if you are not familiar with Alpine Linux.
I had the same issue and created a Dockerfile in a public GitHub repository and connected it with my Docker Hub account and chose an automated build to build my image on each push to the GitHub repository. Then you can easily access your own images with the GitLab CI.
Alpine linux now has a docker-compose package in their "edge" branch, so you can install it this way in .gitlab-ci.yml
I created a simple docker container which has
docker-compose
installed on top ofdocker:latest
. See https://hub.docker.com/r/tmaier/docker-compose/Your
.gitlab-ci.yml
file would look like this:docker-compose now needs more dev-packages, which is described in their official documentation. This is the advised solution, but does not really satisfy me... Too many packages to get it up and running:
I think now it's time to rely on a 3rd-party image or I'd personally configure a nightly build to do the steps above and automatically build a compose-docker-image in our CI for our registry.
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.
Docker also provides an official image:
docker/compose
This is the ideal solution if you don't want to install it every pipeline.
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 withNo such command: sh