在 Scala 中使用 testcontainers 指定容器名称
Specify container name using testcontainers in Scala
使用 dimafeng 的 test containers for Scala 我可以从同一个图像创建多个容器:
class TestWithTwoDatabases extends FunSuite with ForEachTestContainer {
protected val inputContainer: PostgreSQLContainer = PostgreSQLContainer("postgres:13.3")
protected val outputContainer: PostgreSQLContainer = PostgreSQLContainer("postgres:13.3")
override val container: MultipleContainers = MultipleContainers(inputContainer, outputContainer)
// Some integration tests
}
如何在 docker 控制台中区分它们?我目前有:
CONTAINER ID IMAGE NAMES
a2bee9488c02 postgres:13.3 youthful_archimedes # I'd like to have inputContainer here
2c645ed1c54c postgres:13.3 agitated_cori # I'd like to have outputContainer here
在 Scala 中创建容器时如何指定容器的名称?
我不认为这是可能的。而且不清楚你为什么需要它。
测试容器的想法是您可以在代码中使用它们,并且可以通过引用来区分它们,在您的情况下是 inputContainer
和 outputContainer
。它并非设计为以启动框架的形式使用,例如 docker compose
,因此您可以在代码之外的外部使用它。
同时为容器设置一个固定名称将使得无法在 CI 环境中使用共享 docker 引擎 运行 测试声称相同容器名称的测试。
使用 dimafeng 的 test containers for Scala 我可以从同一个图像创建多个容器:
class TestWithTwoDatabases extends FunSuite with ForEachTestContainer {
protected val inputContainer: PostgreSQLContainer = PostgreSQLContainer("postgres:13.3")
protected val outputContainer: PostgreSQLContainer = PostgreSQLContainer("postgres:13.3")
override val container: MultipleContainers = MultipleContainers(inputContainer, outputContainer)
// Some integration tests
}
如何在 docker 控制台中区分它们?我目前有:
CONTAINER ID IMAGE NAMES
a2bee9488c02 postgres:13.3 youthful_archimedes # I'd like to have inputContainer here
2c645ed1c54c postgres:13.3 agitated_cori # I'd like to have outputContainer here
在 Scala 中创建容器时如何指定容器的名称?
我不认为这是可能的。而且不清楚你为什么需要它。
测试容器的想法是您可以在代码中使用它们,并且可以通过引用来区分它们,在您的情况下是 inputContainer
和 outputContainer
。它并非设计为以启动框架的形式使用,例如 docker compose
,因此您可以在代码之外的外部使用它。
同时为容器设置一个固定名称将使得无法在 CI 环境中使用共享 docker 引擎 运行 测试声称相同容器名称的测试。