【发布时间】:2021-07-01 12:11:18
【问题描述】:
我正在使用以下 docker-compose 文件来运行 3 个项目。
- 我的 api 应用程序
- 用于执行数据库迁移的控制台应用程序
- 一个运行单元测试的测试项目。
它们都在同一个解决方案中,因此使用相同的 docker 文件。 我想确保只有在迁移项目成功完成后才能运行测试项目。如何在 docker compose 文件中向控制台应用程序 (myserver-migrations) 添加运行状况检查? 现在我刚刚添加了
depends_on:
- myserver-migration
但这并不能保证迁移成功。有没有办法在控制台应用程序中设置一些状态并在另一个(单元测试)容器中读取它?
services:
myserver:
container_name: myserver
ports:
- "3434:80"
build:
context: .
dockerfile: Dockerfile
target: test
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/health"]
interval: 20s
timeout: 20s
retries: 1
depends_on:
postgres:
condition: service_healthy
myserver-migration:
container_name: myserver-migration
build:
context: .
dockerfile: Dockerfile
target: build
depends_on:
postgres:
condition: service_healthy
myserver:
condition: service_healthy
command: 'dotnet run -p MyServer.Migrations resetdb true'
myserver-tests:
container_name: myserver-tests
build:
context: .
dockerfile: Dockerfile
target: build
depends_on:
- myserver-migration
command: 'dotnet test MyServer.sln'
【问题讨论】:
标签: .net docker .net-core docker-compose