Run docker-compose build in .gitlab-ci.yml

前端 未结 9 1215
臣服心动
臣服心动 2020-12-12 14:06

I have a .gitlab-ci.yml file which contains following:

image: docker:latest

services:
  - docker:dind
         


        
9条回答
  •  时光取名叫无心
    2020-12-12 14:54

    Docker also provides an official image: docker/compose

    This is the ideal solution if you don't want to install it every pipeline.

    Note that in the latest version of GitLab CI/Docker you will likely need to give privileged access to your GitLab CI Runner and configure/disable TLS. See Use docker-in-docker workflow with Docker executor

    variables:
      DOCKER_HOST: tcp://docker:2375/
      DOCKER_DRIVER: overlay2
    
    # Official docker compose image.
    image:
      name: docker/compose:latest
    
    services:
      - docker:dind
    
    before_script:
      - docker version
      - docker-compose version
    
    build:
      stage: build
      script:
        - docker-compose down
        - docker-compose build
        - docker-compose up tester-image
    

    Note that in versions of docker-compose earlier than 1.25:

    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 with No such command: sh

        image:
          name: docker/compose:latest
          entrypoint: ["/bin/sh", "-c"]
    

提交回复
热议问题