Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
744 views
in Technique[技术] by (71.8m points)

Run `docker compose` in GitLab pipeline

I need to deploy an application stack to ECS. To do this, I use the new Docker Compose ECS integration (see e.g. here).

In few words, everything boils up to using the correct docker context and launching the command docker compose up. This is of great help and very quick.

I would like to automate the deploy process in a GitLab pipeline.

What (Docker) image should I use in my pipeline to be able to run the new docker compose command?

Thanks in advance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

As I see it there are now two main options:

  1. You setup a dedicated gitlab runner, that works with the normal shell executor. You then install docker on that machine and also setup the compose-cli according to this manual. Then you can start deploying with the compose command.

  2. You create a docker image that gives you the docker compose command. An example dockerfile could look like this:

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. However it should be possible with gitlabs dind workflow.

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. However the docker daemon is not started.

Note: the resulting image from this Dockerfile is essentially only a modified Docker-in-Docker image. 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. The Gitlab CI image tag would be "docker/compose"

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...