简体   繁体   English

针对 docker-in-docker 运行 docker-compose (dind)

[英]Running docker-compose against docker-in-docker (dind)

In gitlab-ci, I am trying to run docker-compose within a Docker container.在 gitlab-ci 中,我试图在 Docker 容器中运行 docker-compose。 I am using Docker-in-Docker for this.为此,我正在使用 Docker-in-Docker。 To test that everything is working, I just execute a docker info command.为了测试一切正常,我只需执行docker info命令。 However, when I use the docker-compose image as my image, I get the following error when executing docker info :但是,当我使用 docker-compose 图像作为我的图像时,执行docker info时出现以下错误:

ERROR: Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?

If I use docker itself as the image, the docker info command succeeds.如果我使用 docker 本身作为图像,则docker info命令成功。 I'm confused by this since the docker-compose image is based on the docker image.我对此感到困惑,因为 docker-compose 图像基于 docker 图像。

The following.gitlab-ci.yml results in an error from the docker info command:以下.gitlab-ci.yml 导致 docker info 命令出错:

image: docker/compose:debian-1.26.0

stages:
  - test

variables:
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: "/certs"

services:
 - docker:19.03.8-dind

test-provider:
  stage: test
  script:
    - docker info

If I change the image to docker:19.03.8 , the docker info command runs fine.如果我将图像更改为docker:19.03.8 ,则 docker 信息命令运行正常。 Not sure what I'm doing wrong here.不知道我在这里做错了什么。

Try to start dockerd in script section explicity.尝试在脚本部分明确启动 dockerd。 Also you can add script to wait when docker daemon starting succeed.您也可以添加脚本以等待 docker 守护程序启动成功。 Something like:就像是:

sudo dockerd & timeout -t 9 bash -c "while [ ! -S /var/run/docker.sock ]; do sleep 3 && ls -lah /var/run/; done" || exit 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM