I cannot connect to kafka using a test container while the integration is writing a test

Viewed 76

using testcontainer; I'm trying to write an integration test for my project with kafka, postgreSql and elasticsearch, but when I run docker-compose_v2.yml file and run my tests, my tests are successful, but when I use testcontainer, my tests fail, I can't connect to kafka while the tests are running.

1 Answers

Docker Compose should not use IP addresses. You should use Service names directly for endpoint resolution.

Your Compose file is not attached to the TestContainer network when you use Network.newNetwork().

If you want to use Compose in your tests, then do that, not run individual GenericContainers - https://www.testcontainers.org/modules/docker_compose/

Related