All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testcontainers.containers.FixedHostPortGenericContainer Maven / Gradle / Ivy

package org.testcontainers.containers;

import org.jetbrains.annotations.NotNull;

/**
 * Variant of {@link GenericContainer} that allows a fixed port on the docker host to be mapped to a container port.
 *
 * 

Normally this should not be required, and Docker should be allowed to choose a free host port instead. * However, when a fixed host port is absolutely required for some reason, this class can be used to set it.

* *

Callers are responsible for ensuring that this fixed port is actually available; failure will occur if it is * not available - which could manifest as flaky or unstable tests.

*/ public class FixedHostPortGenericContainer> extends GenericContainer { public FixedHostPortGenericContainer(@NotNull String dockerImageName) { super(dockerImageName); } /** * Bind a fixed port on the docker host to a container port * @param hostPort a port on the docker host, which must be available * @param containerPort a port in the container * @return this container */ public SELF withFixedExposedPort(int hostPort, int containerPort) { super.addFixedExposedPort(hostPort, containerPort); return self(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy