为什么在使用testcontainers时,docker镜像会在测试结束时被删除



我正在使用测试容器:

protected static JdbcDatabaseContainer<?> platformPostgresContainer = new PostgreSQLContainer<>("postgres:13")
//      .withReuse(true)
.withInitScript("create-databases.sql");

为什么没有.withReuse(true)postgres:13图像有时会在测试结束时从Docker中消失?

图像由Ryuk删除,如果未指定环境变量TESTCONTAINERS_RYUK_DISABLED=true,则Testcontainers将启动Moby Ryuk容器,该容器在接收SIGTERM时将删除所有带有标签org.testcontainers=true的容器,然后将删除所有没有容器的图像(请参阅Moby Ryuk/main.go中函数prune中的cli.ImagesPrune参数(。因此,如果只有postgres:13容器是由Testcontainers创建的,那么在移除它们之后,postgres:13映像将没有关联的容器,并且也将由Ryuk移除。

根据设计,Testcontainers管理的容器的生命周期可以挂接到测试框架中,但最终不会延长JVM进程的寿命(除非使用alpha功能resusable模式(。

最新更新