I have the following code snippet for kafka container creation using test containers
<code> private GenericContainer<?> createKafkaContainer() {
try (GenericContainer<?> kafkaContainer = new GenericContainer<>(DockerImageName.parse("confluentinc/cp-kafka"))
.withEnv(kafkaProperties)
.withExposedPorts(9092)
.withNetwork(network)
.withNetworkAliases("my-kafka")
.withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(
new HostConfig()
.withPortBindings(new PortBinding(Ports.Binding.bindPort(9092), new ExposedPort(9092)))
))
.withCreateContainerCmdModifier(cmd -> cmd.withHostName("my-kafka"))
.withCreateContainerCmdModifier(cmd -> cmd.withName("my-kafka"))
) {
return kafkaContainer;
}
</code>
<code> private GenericContainer<?> createKafkaContainer() {
try (GenericContainer<?> kafkaContainer = new GenericContainer<>(DockerImageName.parse("confluentinc/cp-kafka"))
.withEnv(kafkaProperties)
.withExposedPorts(9092)
.withNetwork(network)
.withNetworkAliases("my-kafka")
.withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(
new HostConfig()
.withPortBindings(new PortBinding(Ports.Binding.bindPort(9092), new ExposedPort(9092)))
))
.withCreateContainerCmdModifier(cmd -> cmd.withHostName("my-kafka"))
.withCreateContainerCmdModifier(cmd -> cmd.withName("my-kafka"))
) {
return kafkaContainer;
}
</code>
private GenericContainer<?> createKafkaContainer() {
try (GenericContainer<?> kafkaContainer = new GenericContainer<>(DockerImageName.parse("confluentinc/cp-kafka"))
.withEnv(kafkaProperties)
.withExposedPorts(9092)
.withNetwork(network)
.withNetworkAliases("my-kafka")
.withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(
new HostConfig()
.withPortBindings(new PortBinding(Ports.Binding.bindPort(9092), new ExposedPort(9092)))
))
.withCreateContainerCmdModifier(cmd -> cmd.withHostName("my-kafka"))
.withCreateContainerCmdModifier(cmd -> cmd.withName("my-kafka"))
) {
return kafkaContainer;
}
I also create a custom network like this at class level
<code>Network network = Network.newNetwork();
</code>
<code>Network network = Network.newNetwork();
</code>
Network network = Network.newNetwork();
When I run my spring boot based test from mac, I get below error:
<code>2024-12-07T21:14:12.895-08:00 WARN 74816 --- [ntainers-wait-0] .c.w.i.InternalCommandPortListeningCheck : An exception while executing the internal check: Container.ExecResult(exitCode=137, stdout=, stderr=Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connection to ::1 failed: Connection refused.
Ncat: Trying next address...
Ncat: Connection refused.
/bin/bash: connect: Connection refused
/bin/bash: /dev/tcp/localhost/9092: Connection refused
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connection to ::1 failed: Connection refused.
Ncat: Trying next address...
Ncat: Connection refused.
/bin/bash: connect: Connection refused
/bin/bash: /dev/tcp/localhost/9092: Connection refused
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connection to ::1 failed: Connection refused.
Ncat: Trying next address...
Ncat: Connection refused.
/bin/bash: connect: Connection refused
/bin/bash: /dev/tcp/localhost/9092: Connection refused
</code>
<code>2024-12-07T21:14:12.895-08:00 WARN 74816 --- [ntainers-wait-0] .c.w.i.InternalCommandPortListeningCheck : An exception while executing the internal check: Container.ExecResult(exitCode=137, stdout=, stderr=Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connection to ::1 failed: Connection refused.
Ncat: Trying next address...
Ncat: Connection refused.
/bin/bash: connect: Connection refused
/bin/bash: /dev/tcp/localhost/9092: Connection refused
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connection to ::1 failed: Connection refused.
Ncat: Trying next address...
Ncat: Connection refused.
/bin/bash: connect: Connection refused
/bin/bash: /dev/tcp/localhost/9092: Connection refused
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connection to ::1 failed: Connection refused.
Ncat: Trying next address...
Ncat: Connection refused.
/bin/bash: connect: Connection refused
/bin/bash: /dev/tcp/localhost/9092: Connection refused
</code>
2024-12-07T21:14:12.895-08:00 WARN 74816 --- [ntainers-wait-0] .c.w.i.InternalCommandPortListeningCheck : An exception while executing the internal check: Container.ExecResult(exitCode=137, stdout=, stderr=Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connection to ::1 failed: Connection refused.
Ncat: Trying next address...
Ncat: Connection refused.
/bin/bash: connect: Connection refused
/bin/bash: /dev/tcp/localhost/9092: Connection refused
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connection to ::1 failed: Connection refused.
Ncat: Trying next address...
Ncat: Connection refused.
/bin/bash: connect: Connection refused
/bin/bash: /dev/tcp/localhost/9092: Connection refused
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connection to ::1 failed: Connection refused.
Ncat: Trying next address...
Ncat: Connection refused.
/bin/bash: connect: Connection refused
/bin/bash: /dev/tcp/localhost/9092: Connection refused
If I don’t provide custom network, and I use host.docker.internal, things work just fine. What is also confusing is, do I need my ryuk to be on same network and need to do something explicitly for it? I am not bringing up ryuk explicitly, but I know it gets created when I launch my test.