-
-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to specify container to host port mappings #94
Comments
You need to set the port in Sarama to 9092, you can get the current port mapping by doing, in the case of mysql,
For kafka this is probably something like |
Thanks for the reply @arekkas. In regards to mysql this would certainly be the solution, however things have gotten a bit trickier since trying dockertest with Kafka. I use
For the moment, I have "solved" the issue by using fsouza/go-dockerclient directly. This allows for specifying the host ports the container ports should be mapped to: https://github.com/adbourne/go-archetype-kafka-processor/blob/master/app_integration_test.go#L124 If I understand correctly, as dockertest uses fsouza/go-dockerclient, it should be possible to use a similar approach to allow for dockertest to offer this feature. Perhaps by allowing a ":" to be present in an ExposedPorts declaration such that a host port and container port can be specified e.g |
Yes, this was actually the case until the v3 release, but was replaced in favor of dynamic port allocation which avoids port conflicts, which happened a lot. I'm open to having an option to force specific ports though. |
Same problem here. I understand issue with port conflicts during testing. Is there way to know port beforehand so I can configure Kafka properly via environment variables? Is there way to use some sort of substitutions in Env variables? Is there way to run a command to form environment variable? |
For people looking for answer. It's possible to get fixed port mappings using Also, got single container variant working:
|
I notice the
ExposedPorts
functionality, that allows for a container port to be specified such that it is mapped to a random host port e.g0.0.0.0:32911->9092/tcp
. Is there a way to specify the port mappings such that the container port is mapped to a specific host port e.g0.0.0.0:9092->9092/tcp
?I'm attempting to use dockertest to spin up an Apache Kafka container spotify/kafka, for use in an integration test. The app is making use of the Shopify/sarama Kafka client. As expected, dockertest spins up the Kafka container successfully. In fact, all works fine up until Sarama attempts to consume from the Kafka topic. The reason for this is that the Kafka broker advertises its port number to Sarama, which Sarama then uses, but it's the container port and not the host port. For example, dockertest spins up a Kafka container with port mappings
0.0.0.0:32911->9092/tcp
, Sarama connects initially on port 32911 and queries for the broker information, "localhost:9092" is returned to Sarama, Sarama attempts to connect but fails as port 9092 is not available.I'm sure there's probably a more elegant solution rather than ensuring that the container port is mapped to the exact same host port, but specific port mappings would certainly be a very useful feature in dockertest.
For reference, the code I'm working on can be found hereThe text was updated successfully, but these errors were encountered: