How to run docker-compose inside docker in docker which runs inside gitlab-runner container?

泄露秘密 提交于 2020-08-27 06:04:29

问题


I have a gitlab runner inside a docker container, runs fine if I run an image like nginx. But now I tried to run docker in docker (dind) inside the gitlab runner and I want to run docker-compose inside the dind. Docker info runs fine, but if I try to run docker-compose I get an permission-denied error.

I linked the /usr/local/bin/docker-compose file to the gitlab runner container and enter it in the volumes parameter in the runner config.toml file.

If I try to run sudo it ends with an unknown command error, so that could not be the solution.

Do I have to link some file more or are the to many nested containers?


回答1:


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



回答2:


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 python-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 add py-pip
  - apk add python-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


来源:https://stackoverflow.com/questions/48630005/how-to-run-docker-compose-inside-docker-in-docker-which-runs-inside-gitlab-runne

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!