Martinffx
Martinffx

Reputation: 2476

gitlab.com CI docker-compose

I've dockerised my application and use docker-compose to run it locally. I'd like to use the same docker-compose commands I use locally to build and test my application on the CI runner but I can't seem to find any documentation on how?

I'm using gitlab.com and there documentation says you should just use the docker image. Only docker-compose doesn't seem to come with the standard image any more...

What's the best approach to use docker-compose with GitLab CI?

EDIT: Use case

.gitlab-ci.yml

image: docker:latest

variables:
  DOCKER_DRIVER: overlay
  WORKER_TEST_IMAGE: registry.gitlab.com/org/project/worker:$CI_COMMIT_REF_NAME
  WORKER_RELEASE_IMAGE: registry.gitlab.com/org/project/worker:latest

services:
  - postgres:9.6.3
  - docker:dind

stages:
- build
- test
- release
- deploy

before_script:
  - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY

build_worker:
  stage: build
  script:
    - docker build --pull -t $WORKER_TEST_IMAGE .
    - docker push $WORKER_TEST_IMAGE

test_worker:
  stage: test
  script:
    - docker pull $WORKER_TEST_IMAGE
    # I need a way to connect the postgres service to the image I'm 
    # trying to run. Which doesn't seem possible?
    # - docker-compose run worker dockerize -wait tcp://postgres:5432 nosetests
    - docker run $WORKER_TEST_IMAGE dockerize -wait tcp://postgres:5432 nosetests
...

I feel like Gitlab CI is making me reimplement docker-compose because they don't support it?

Upvotes: 3

Views: 1622

Answers (1)

madnight
madnight

Reputation: 418

Gitlab CI has its own docker syntax and there is no support for docker-compose. So docker-compose will only work if you use a mechanism called dind (docker in docker), where you have to mount the docker socket of the host system into your CI runners. Sooner or later you will discover that this approach has serious limitations, might introduce more runner configuration and lacks documentation.

Although possible, you really should stick to the offical gitlab way. Carefully read https://docs.gitlab.com/ce/ci/docker/using_docker_images.html and you will be able to easily use multiple docker containers in a similar way as docker-compose.

Upvotes: 4

Related Questions