Search code examples
spring-boottestcontainers

Testcontainers cant seem to communicate - connection refused


so i have one container set up like

genericContainer
                    .withImagePullPolicy(PullPolicy.alwaysPull())
                    .withExposedPorts(SPRING_BOOT_PORT)
                    .withNetwork(NETWORK)
                    .withAccessToHost(true);
             

this starts up fine and i can ping it.

I have another container

S3MockContainer(DockerImageName.parse("adobe/s3mock:2.4.13"))
            .withInitialBuckets(S3_BUCKET_NAME)
            .withNetwork(NETWORK);

I cant seem to connect or ping the s3Mock container from within my first test container. I have tried passing in the s3MockContainer.gethost() + getFirstMappedPort()

but it just is not able to connect?


Solution

  • Both containers are in the same network. So, in that case, you can use the real ports.

    First, update S3MockContainer by adding withNetworkAliases("s3"), then you can use s3:9090 in your spring boot app in order to connect to.

    Also, I don't think you need withAccessToHost(true).