Search code examples
dockerdocker-composegitlabgitlab-ci

How to install docker-compose on CI runner environment where you're trying to build your Docker images


I'm trying to install docker-compose in before_script to build my docker images. I'm relatively new to building pipeline. Not sure what mistake I'm making here as I still get

$ docker-compose --version
/bin/sh: eval: line 147: docker-compose: not found
stages:
  - build

build:
  stage: build
  image: docker:latest
  before_script:
    - apk add --no-cache curl
    - curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    - docker-compose --version
  script:
    - echo "Building and tagging Docker"
    - docker-compose -f docker-compose.yml build
    - docker tag frontend:latest $DOCKER_REGISTRY_URL/frontend:$IMAGE_TAG
    - docker tag server:latest $DOCKER_REGISTRY_URL/server:$IMAGE_TAG

I feel like something is mixed up in before_script.


Solution

  • You can just install directly using apk. Try this:

    stages:
      - build
    
    build:
      stage: build
      image: docker:latest
      before_script:
        - apk add docker-compose
        - docker-compose --version
      script:
        - echo "Ready to run docker-compose."
    

    enter image description here