使用带有CI的docker-compose-如何处理退出代码和守护程序链接的容器? [英] Using docker-compose with CI - how to deal with exit codes and daemonized linked containers?

查看:113
本文介绍了使用带有CI的docker-compose-如何处理退出代码和守护程序链接的容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我们的Jenkins代理为我们的每个Rails项目生成一个docker-compose.yml,然后运行docker-compose。 docker-compose.yml具有一个主要的 Web容器,其中包含rbenv和我们所有其他的Rails依赖项。它链接到包含测试Postgres DB的数据库容器。

Right now our Jenkins agents generate a docker-compose.yml for each of our Rails projects and then run docker-compose up. The docker-compose.yml has a main "web" container that has rbenv and all of our other Rails dependencies inside. It is linked to a DB container that contains the test Postgres DB.

问题是当我们需要实际运行测试并生成退出代码时出现的。仅当测试脚本返回exit 0时,我们的CI服务器才会部署,但是docker-compose始终返回0,即使其中一个容器命令失败。

The problem comes when we need to actually run the tests and generate exit codes. Our CI server will only deploy if the test script returns exit 0, but docker-compose always returns 0, even if one of the container commands fail.

另一个问题是即使Web容器完成了运行测试后,数据库容器也会无限期运行,因此 docker-compose up 永远不会返回。

The other issue is that the DB container runs indefinitely, even after the web container is done running the tests, so docker-compose up never returns.

有没有一种方法可以在此过程中使用docker-compose?我们需要能够运行容器,但是在完成网络容器后退出并返回退出代码。现在,我们使用docker手动启动数据库容器并使用--link选项运行Web容器。

Is there a way we can use docker-compose for this process? We would need to be able to run the containers, but exit after the web container is complete and return it's exit code. Right now we are stuck manually using docker to spin up the DB container and run the web container with the --link option.

推荐答案

1.12.0 版本开始,您可以使用-退出代码自选项。

Since version 1.12.0, you can use the --exit-code-from option.

来自文档


-从服务中退出代码

--exit-code-from SERVICE

返回所选服务容器的退出代码。表示--abort-on-container-exit。

Return the exit code of the selected service container. Implies --abort-on-container-exit.

这篇关于使用带有CI的docker-compose-如何处理退出代码和守护程序链接的容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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