How to run docker-compose inside docker in docker which runs inside gitlab-runner container?
In order to have docker-compose
, you need to install it for image docker, which is of version 18.09.6, build 481bc77 at the time of writing.
Since docker-compose version 1.24.0, you also need the following dependencies for docker-compose to be installed on alpine:
apk add py-pip python3-dev libffi-dev openssl-dev gcc libc-dev make
Here is a sample .gitlab-ci.yml
:
image: docker:stable
stages:
- deploy
services:
- docker:dind
before_script:
- apk update
- apk add py-pip python3-dev libffi-dev openssl-dev gcc libc-dev make
- pip install docker-compose
deploy_app:
stage: deploy
script:
- docker-compose down
- docker-compose up -d
if you are using dind it means docker is working OK, now you just have to install docker-compose that is just simple python package and you can do it in before_script
.gitlab-ci.yml
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
stages:
- test
before_script:
- apk add --no-cache py-pip
- pip install docker-compose
- docker info
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN docker.registry.com
test:
stage: test
script:
- cp .env.sample .env # copy environement variable
- docker-compose up -d
# run some test here