docker - 在本地环境中运行 testcontainer test OK 但在 jenkins 中失败
问题描述
背景
在我的应用程序中,它需要连接到 zookeeper 以获取一些有用的信息。因此,我在集成测试中启动了一个 Zookeeper 容器,并使用 -p 2859:2181 之类的端口绑定。
zookeeper = new GenericContainer<>("zookeeper:3.6.1")
.withEnv("ZOOKEEPER_CLIENT_PORT", "2181")
.withExposedPorts(2181);
zookeeper.setPortBindings(Arrays.asList("2859:2181"));
zookeeper.start();
然后我使用以下命令运行测试。它顺利连接到 localhost:2859 没有任何问题。
mvn -Dtest=xxxIntegrationTest.java test
问题
但是,当我使用 jenkins 使用相同的命令运行相同的测试时,它无法连接到 localhost:2859,抱怨说
2020-10-28 12:16:04.282 INFO [main-SendThread(localhost:2859)] Opening socket connection to server localhost/127.0.0.1:2859. Will not attempt to authenticate using SASL (unknown error)
2020-10-28 12:16:04.283 WARN [main-SendThread(localhost:2859)] Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:350)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1068)
我不知道为什么它在这两个场景中表现不同。谁能给我一些建议?
解决方案
推荐阅读
- swift - 使用 firebase 数据库和存储下载数据时索引超出范围异常
- python - 如何检测空物体?
- liquibase - Liquibase 试图创建同一个表两次
- lucene - 您如何从 Lucene 的 FeatureField 中读取单个特征的值?
- intershop - Intershop 7.10:发布构建期间的警告消息
- javascript - 使用 v-model 获取方法的结果
- c - 如何在内存中重新映射文件 mmap(2),如 shmget
- java - 如何在 Java 中为一系列 API 调用构建自定义的中间操作管道?
- ruby-on-rails - 我可以使用 Rails 连接到服务器的 postgres,但无法通过命令行
- angular - 如何在 ngFor Angular 6 中获得不同的动画行为