1 回答

TA貢獻1779條經驗 獲得超6個贊
Informix 的 docker 鏡像配置錯誤。在 docker 容器中啟動的服務器只會監聽主機名,而不是本地主機。Testcontainers 使用“localhost”作為網絡接口來連接到您的容器。因此,當您使用.withExposedPorts(9088)該端口時,該端口實際上并未暴露在 TestContainers 可以連接到的網絡接口上。
這就是為什么即使您等待日志消息,您仍然很可能遇到問題,您也在端口上等待并且它永遠不可用。
好消息是,這個問題現在已經修復,可以通過下載最新的 Informix docker 鏡像來使用
ibmcom/informix-developer-database:latest獲取最新的 14.10 docker 鏡像
下面是我運行的代碼,用于驗證新圖像是否與 TestContainers 一起更好地工作。
public class DockerTest {
GenericContainer<?>container = new GenericContainer<>("ibmcom/informix-developer-database:latest")
.withExposedPorts(9088, 9089, 27017, 27018, 27883).withEnv("LICENSE", "accept");
@Test
public void testIfxContainer() throws Exception {
container.start();
System.out.println("Informix started");
//test the connection
try(Connection c = DriverManager.getConnection("jdbc:informix-sqli:localhost:" + container.getFirstMappedPort() + "/sysmaster:user=informix;password=your-password")) {
try(Statement s = c.createStatement(); ResultSet rs = s.executeQuery("SELECT FIRST 10 tabname from systables");) {
while(rs.next()) {
System.out.println(r.getString(1));
}
}
}
}
}
添加回答
舉報