All posts (1)

Dynamic containers dynamic ports

Running integration tests locally with Docker on fixed ports is not always possible due to port conflicts. This is especially true when running tests in shared CI environment. Fortunately, testcontainers allow to start Docker containers listening on a random port. Here is an example: // create and start container val container = new GenericContainer("softwaremill/elasticmq-native") .withExposedPorts(9324) .withReuse(true) container.start() // create sqsClient val sqsPort = container.getMappedPort(9324) val clientBuilder = SqsAsyncClient.builder() .credentialsProvider(DefaultCredentialsProvider.create()) .region(Region.EU_CENTRAL_1) .

logo   Never miss a story, subscribe to our newsletter