testcontainers

Why docker image is removed at the end of the tests when using testcontainers?


I'm using Testcontainers:

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

Why without the .withReuse(true) the postgres:13 image sometimes disappears from Docker at the end of the tests?


Solution

  • This is by design, the lifecycle of containers managed by Testcontainers can be hooked into the test framework, but will ultimately not extend the life of the JVM process (unless the alpha feature resusable mode is used).