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

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

问题描述

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

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.

当我们需要实际运行测试并生成退出代码时,问题就出现了.我们的 CI 服务器仅在测试脚本返回 exit 0 时才会部署,但 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?我们需要能够运行容器,但在 Web 容器完成后退出并返回它的退出代码.现在我们被困在使用 docker 手动启动 DB 容器并使用 --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 版本开始,您可以使用 --exit-code-from 选项.

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

来自文档:

--exit-code-from SERVICE

--exit-code-from SERVICE

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

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

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

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