如何在gitlab-runner容器中运行的docker中的docker中运行docker-compose? [英] How to run docker-compose inside docker in docker which runs inside gitlab-runner container?

查看:364
本文介绍了如何在gitlab-runner容器中运行的docker中的docker中运行docker-compose?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在docker容器中有一个gitlab运行程序,如果运行类似nginx的图像,则运行良好。但是现在我尝试在gitlab运行程序内的docker(dind)中运行docker,我想在dind中运行docker-compose。 Docker信息运行正常,但是如果我尝试运行docker-compose,则会收到权限拒绝的错误。

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.

我将/ usr / local / bin / docker-compose文件链接到gitlab运行器容器,并将其输入到运行器config.toml文件的volumes参数中。

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.

如果我尝试运行sudo,它将以未知的命令错误结尾,因此这不是解决方案。

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?

推荐答案

如果您使用的是dind,则表示docker工作正常,现在您只需要安装docker-compose这只是简单的python程序包,就可以在before_script中完成

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

这篇关于如何在gitlab-runner容器中运行的docker中的docker中运行docker-compose?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆