I want to integration test few services running on docker environment. They have to talk each other as they are connected. So I need to somehow expose port between each other. Is this setup possible using test containers library? I did not find any docks on it.
Tested app running locally, which will connect to dockerised servers:
To make it even harder backend one server needs to talk to mysql service. Is this possible using testcontainers?
Testcontainers supports networks, there are a few examples in the tests .
You need to first create a network (via Network.newNetwork()
), and then use withNetwork
/ withNetworkAliases
to "connect" your containers into the same network.
Generally, when network communication between containers is required, a network should be created at docker level and containers should share it.
Things can be simplified by using docker-compose
, which by default creates a network for all services declared in docker-compose
file. Then containers can communicate via their service name.
I have never used Testcontainers project but I see in docs that has a docker-compose module .
Quoting from above url:
Testcontainers will spin up a small 'ambassador' container, which will proxy between the Compose-managed containers and ports that are accessible to your tests. This is done using a separate, minimal container that runs socat as a TCP proxy.
There is also an example that you can base on, on docs url.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.