docker-compose在testing后退出depends_on服务

一旦依赖容器完成,如何获取服务容器退出?

我有一个运行在app_unittestbot容器中的testing套件,它依赖于运行在不同容器中的postgresql数据库服务器(postgres:9.5-alpine)。 一旦testing套件退出,我想检查testing套件的返回代码并停止数据库容器。 使用下面的docker-compose.yml,数据库服务容器永远不会停止。

泊坞窗,compose.yml

version: '2.1' services: app_postgresql95: build: ./postgresql95/ ports: - 54321:5432 app_unittestbot: command: /root/wait-for-it.sh app_postgresql95:5432 --timeout=60 -- nose2 tests build: ./unittestbot/ links: - app_postgresql95 volumes: - /app/src:/src depends_on: - 'app_postgresql95' 

你可以运行docker-compose up --abort-on-container-exit来组成停止所有容器,如果其中任何一个退出的话。 这可能会解决你的用例。

对于更有弹性的东西,我可能会将其分成两个组合文件,这样postgresql上的中止不会被意外注册为成功的testing。 那么你只需要按照你需要的顺序运行这些文件:

 docker-compose -f docker-compose.yml up -d docker-compose -f docker-compose.test.yml up docker-compose -f docker-compose.yml down