Skip to content

Commit

Permalink
do not implicitly connect to Kafka network (#2139)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bsideup committed Dec 6, 2019
1 parent 0adacde commit bb0554b
Showing 1 changed file with 1 addition and 10 deletions.
Expand Up @@ -39,6 +39,7 @@ public KafkaContainer() {
public KafkaContainer(String confluentPlatformVersion) {
super(TestcontainersConfiguration.getInstance().getKafkaImage() + ":" + confluentPlatformVersion);

super.withNetwork(Network.SHARED);
withExposedPorts(KAFKA_PORT);

// Use two listeners with different names, it will force Kafka to communicate with itself via internal
Expand Down Expand Up @@ -70,16 +71,6 @@ public Network getNetwork() {
"Consider using KafkaContainer#withNetwork",
new Exception("Deprecated method")
);
Network network = Network.SHARED;
super.withNetwork(network);

if (getContainerId() != null) {
dockerClient.connectToNetworkCmd()
.withContainerId(getContainerId())
.withNetworkId(network.getId())
.exec();
}
return network;
}
return super.getNetwork();
}
Expand Down

0 comments on commit bb0554b

Please sign in to comment.