Here is docker-compose file:
app:
image: myimage
depends_on:
- nsqd
- localstack
command: ["run.sh"]
environment:
- "DYNAMODB=http://localstack:4569"
ports:
- 8080:8080
nsqd:
image: nsqio/nsq
command: /run
ports:
- "4150:4150"
- "4151:4151"
localstack:
image: localstack/localstack:latest
ports:
- 4569:4569
environment:
SERVICES: dynamodb
DATA_DIR: /tmp/localstack/data
HOSTNAME: localstack
This compose file is run in java junit test before any test method is run :
@Before
public void setUp() throws Exception {
new DockerComposeContainer(new File("docker-compose.yaml"))
.withExposedService("nsqd", 4150, Wait.forListeningPort())
.withExposedService("localstack", 4569, Wait.forListeningPort())
.withExposedService("app", 8080, Wait.forListeningPort())
.start();
}
When all test methods run one by one there are no problems at all. But when I try to run more than 2 test same time I got errors like that:
ERROR: for localstack Cannot start service localstack: driver failed programming external connectivity on endpoint hwfdrbmwpwn1_localstack_1 (e33d2a3098e74b1b8d87e3e595d9d9504ccddd4fe9c0605b20ebd3f22f50daa5): Bind for 0.0.0.0:4569 failed: port is already allocated
ERROR: for nsqlookupd Cannot start service nsqlookupd: driver failed programming external connectivity on endpoint hwfdrbmwpwn1_nsqlookupd_1 (fe62cec02a23a184d65b3f02776a14d77fdfbe639645ea0a11e07e8f11010e37): Bind for 0.0.0.0:4161 failed: port is already allocated
And those port differs from withExposedService
function. From other side all service from compose file started in isolated network
so there are should not be any conflicts but they exist. Can any bpody explain what is going on with ports?
What is the additional config should be provided to testcontainers to run docker-compose services multiple times same time?