Skip to content

Commit bb0554b

Browse files
authored
do not implicitly connect to Kafka network (#2139)
Apparently, there is a bug(?) in Docker that sometimes(!) re-assigns random ports when container is connect to network. It means that we cannot lazily connect KafkaContainer to network in case it wasn't set.
1 parent 0adacde commit bb0554b

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

modules/kafka/src/main/java/org/testcontainers/containers/KafkaContainer.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public KafkaContainer() {
3939
public KafkaContainer(String confluentPlatformVersion) {
4040
super(TestcontainersConfiguration.getInstance().getKafkaImage() + ":" + confluentPlatformVersion);
4141

42+
super.withNetwork(Network.SHARED);
4243
withExposedPorts(KAFKA_PORT);
4344

4445
// Use two listeners with different names, it will force Kafka to communicate with itself via internal
@@ -70,16 +71,6 @@ public Network getNetwork() {
7071
"Consider using KafkaContainer#withNetwork",
7172
new Exception("Deprecated method")
7273
);
73-
Network network = Network.SHARED;
74-
super.withNetwork(network);
75-
76-
if (getContainerId() != null) {
77-
dockerClient.connectToNetworkCmd()
78-
.withContainerId(getContainerId())
79-
.withNetworkId(network.getId())
80-
.exec();
81-
}
82-
return network;
8374
}
8475
return super.getNetwork();
8576
}

0 commit comments

Comments
 (0)