简体   繁体   English

在 GitLab 管道中运行 docker compose

[英]Run `docker compose` in GitLab pipeline

I need to deploy an application stack to ECS.我需要将应用程序堆栈部署到 ECS。 To do this, I use the new Docker Compose ECS integration (see eg here ).为此,我使用了新的 Docker Compose ECS 集成(参见例如此处)。

In few words, everything boils up to using the correct docker context and launching the command docker compose up .简而言之,一切都归结为使用正确的docker context并启动命令docker compose up This is of great help and very quick.这很有帮助,而且非常快。

I would like to automate the deploy process in a GitLab pipeline.我想自动化 GitLab 管道中的部署过程。

What (Docker) image should I use in my pipeline to be able to run the new docker compose command?我应该在管道中使用什么(Docker)映像才能运行新的docker compose命令?

Thanks in advance.提前致谢。

So to elaborate on the idea from the comments:因此,从评论中详细说明这个想法:

The docker compose binary is direcly woven together with the docker command itself, essentially being an extension to it. docker compose二进制直接与docker命令本身结合在一起,本质上是它的扩展。

As I see it there are now two main options:正如我所看到的,现在有两个主要选择:

  1. You setup a dedicated gitlab runner, that works with the normal shell executor.您设置了一个专用的 gitlab 运行器,它与普通的 shell 执行器一起工作。 You then install docker on that machine and also setup the compose-cli according to this manual.然后在该机器上安装 docker 并根据手册设置 compose-cli。 Then you can start deploying with the compose command.然后您可以使用 compose 命令开始部署。

  2. You create a docker image that gives you the docker compose command.您创建一个 docker 映像,该映像为您提供docker compose命令。 An example dockerfile could look like this:示例 dockerfile 可能如下所示:

FROM docker

RUN apk add curl
RUN apk add tar
RUN curl -L https://github.com/docker/compose-cli/releases/download/v1.0.6/docker-linux-amd64.tar.gz -O
RUN tar xzf docker-linux-amd64.tar.gz
RUN chmod +x docker/docker
RUN ln -s /usr/local/bin/docker /usr/bin/com.docker.cli

Now, the difficulty there is to manage to have the docker daemon available.现在,很难让 docker 守护程序可用。 However it should be possible with gitlabs dind workflow.但是,gitlabs dind工作流程应该是可能的。

After starting the container with docker run --rm --privileged -it <containername> sh the docker compose command in my example would be available as ./docker compose as I did not add the new docker binary to any path.使用docker run --rm --privileged -it <containername> sh启动容器后,我的示例中的docker compose命令将作为./docker compose使用,因为我没有将新的 Z05B6053C41A2134E6ZB 二进制文件添加到任何路径 3B6053C41A2130AFD6FC3B158BDA4E6Z However the docker daemon is not started.但是 docker 守护程序未启动。

Note: the resulting image from this Dockerfile is essentially only a modified Docker-in-Docker image.注意:此 Dockerfile 生成的镜像本质上只是一个修改后的 Docker-in-Docker 镜像。 So it should work, but I was not able to test it.所以它应该可以工作,但我无法测试它。

Docker itself provides an image on their docker hub that offers docker-compose functionality. Docker 本身在其 docker 集线器上提供了一个图像,该集线器提供了 docker-compose 功能。 The Gitlab CI image tag would be "docker/compose" Gitlab CI 图像标签将是“docker/compose”

https://hub.docker.com/r/docker/compose https://hub.docker.com/r/docker/compose

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

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