public interface Container<SELF extends Container<SELF>> extends LinkableContainer, ContainerState
Modifier and Type | Interface and Description |
---|---|
static class |
Container.ExecResult
Class to hold results from a "docker exec" command
|
STATE_HEALTHY
Modifier and Type | Method and Description |
---|---|
void |
addEnv(java.lang.String key,
java.lang.String value)
Add an environment variable to be passed to the container.
|
void |
addExposedPort(java.lang.Integer port)
Add an exposed port.
|
void |
addExposedPorts(int... ports)
Add exposed ports.
|
default void |
addFileSystemBind(java.lang.String hostPath,
java.lang.String containerPath,
BindMode mode)
Deprecated.
|
void |
addFileSystemBind(java.lang.String hostPath,
java.lang.String containerPath,
BindMode mode,
SelinuxContext selinuxContext)
Deprecated.
|
void |
addLink(LinkableContainer otherContainer,
java.lang.String alias)
|
default void |
followOutput(java.util.function.Consumer<OutputFrame> consumer)
Follow container output, sending each frame (usually, line) to a consumer.
|
default void |
followOutput(java.util.function.Consumer<OutputFrame> consumer,
OutputFrame.OutputType... types)
Follow container output, sending each frame (usually, line) to a consumer.
|
java.util.List<com.github.dockerjava.api.model.Bind> |
getBinds() |
java.lang.String[] |
getCommandParts() |
@NonNull java.lang.String |
getDockerImageName()
Get image name.
|
java.util.List<java.lang.String> |
getEnv()
Deprecated.
use getEnvMap
|
java.util.Map<java.lang.String,java.lang.String> |
getEnvMap() |
java.util.List<java.lang.String> |
getExtraHosts() |
java.util.concurrent.Future<java.lang.String> |
getImage() |
java.util.Map<java.lang.String,LinkableContainer> |
getLinkedContainers()
|
java.util.List<java.lang.String> |
getPortBindings() |
java.lang.String |
getTestHostIpAddress()
Deprecated.
|
default SELF |
self() |
void |
setBinds(java.util.List<com.github.dockerjava.api.model.Bind> binds) |
void |
setCommand(java.lang.String... commandParts)
Set the command that should be run in the container.
|
void |
setCommand(@NonNull java.lang.String command)
Set the command that should be run in the container.
|
void |
setCommandParts(java.lang.String[] commandParts) |
void |
setDockerImageName(@NonNull java.lang.String dockerImageName)
Resolve Docker image and set it.
|
void |
setEnv(java.util.List<java.lang.String> env) |
void |
setExposedPorts(java.util.List<java.lang.Integer> exposedPorts) |
void |
setExtraHosts(java.util.List<java.lang.String> extraHosts) |
void |
setImage(java.util.concurrent.Future<java.lang.String> image) |
void |
setLinkedContainers(java.util.Map<java.lang.String,LinkableContainer> linkedContainers)
|
void |
setPortBindings(java.util.List<java.lang.String> portBindings) |
void |
setWaitStrategy(WaitStrategy waitStrategy) |
SELF |
waitingFor(@NonNull WaitStrategy waitStrategy)
Specify the
WaitStrategy to use to determine if the container is ready. |
default SELF |
withClasspathResourceMapping(java.lang.String resourcePath,
java.lang.String containerPath,
BindMode mode)
Deprecated.
|
SELF |
withClasspathResourceMapping(java.lang.String resourcePath,
java.lang.String containerPath,
BindMode mode,
SelinuxContext selinuxContext)
Deprecated.
|
SELF |
withCommand(java.lang.String... commandParts)
Set the command that should be run in the container
|
SELF |
withCommand(java.lang.String cmd)
Set the command that should be run in the container
|
SELF |
withCopyFileToContainer(MountableFile mountableFile,
java.lang.String containerPath)
Deprecated.
Use
withCopyToContainer(Transferable, String) instead |
SELF |
withCopyToContainer(Transferable transferable,
java.lang.String containerPath)
Set the content to be copied before starting a created container
|
SELF |
withEnv(java.util.Map<java.lang.String,java.lang.String> env)
Add environment variables to be passed to the container.
|
default SELF |
withEnv(java.lang.String key,
java.util.function.Function<java.util.Optional<java.lang.String>,java.lang.String> mapper)
Add an environment variable to be passed to the container.
|
SELF |
withEnv(java.lang.String key,
java.lang.String value)
Add an environment variable to be passed to the container.
|
SELF |
withExposedPorts(java.lang.Integer... ports)
Set the ports that this container listens on
|
SELF |
withExtraHost(java.lang.String hostname,
java.lang.String ipAddress)
Add an extra host entry to be passed to the container
|
default SELF |
withFileSystemBind(java.lang.String hostPath,
java.lang.String containerPath)
Deprecated.
|
SELF |
withFileSystemBind(java.lang.String hostPath,
java.lang.String containerPath,
BindMode mode)
Deprecated.
|
SELF |
withImagePullPolicy(ImagePullPolicy policy)
Set the image pull policy of the container
|
SELF |
withLabel(java.lang.String key,
java.lang.String value)
Add a label to the container.
|
SELF |
withLabels(java.util.Map<java.lang.String,java.lang.String> labels)
Add labels to the container.
|
SELF |
withLogConsumer(java.util.function.Consumer<OutputFrame> consumer)
Attach an output consumer at container startup, enabling stdout and stderr to be followed, waited on, etc.
|
SELF |
withMinimumRunningDuration(java.time.Duration minimumRunningDuration)
Only consider a container to have successfully started if it has been running for this duration.
|
SELF |
withNetwork(Network network)
Set the network for this container, similar to the
--network <name>
option on the docker CLI. |
SELF |
withNetworkAliases(java.lang.String... aliases)
Set the network aliases for this container, similar to the
--network-alias <my-service>
option on the docker CLI. |
SELF |
withNetworkMode(java.lang.String networkMode)
Set the network mode for this container, similar to the
--net <name>
option on the docker CLI. |
SELF |
withPrivilegedMode(boolean mode)
Set the privilegedMode mode for the container
|
SELF |
withStartupCheckStrategy(StartupCheckStrategy strategy)
Set the startup check strategy used for checking whether the container has started.
|
SELF |
withStartupTimeout(java.time.Duration startupTimeout)
Set the duration of waiting time until container treated as started.
|
SELF |
withVolumesFrom(Container container,
BindMode mode)
Adds container volumes.
|
SELF |
withWorkingDirectory(java.lang.String workDir)
Set the working directory that the container should use on startup.
|
getContainerName
copyFileFromContainer, copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getContainerId, getContainerInfo, getContainerIpAddress, getCurrentContainerInfo, getDockerClient, getExposedPorts, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunning
default SELF self()
void setCommand(@NonNull @NonNull java.lang.String command)
withCommand(String)
for building a container in a fluent style.command
- a command in single string format (will automatically be split on spaces)void setCommand(@NonNull java.lang.String... commandParts)
withCommand(String...)
for building a container in a fluent style.commandParts
- a command as an array of string partsvoid addEnv(java.lang.String key, java.lang.String value)
withEnv(String, String)
for building a container in a fluent style.key
- environment variable keyvalue
- environment variable value@Deprecated default void addFileSystemBind(java.lang.String hostPath, java.lang.String containerPath, BindMode mode)
GenericContainer.withCopyToContainer(Transferable, String)
withFileSystemBind(String, String, BindMode)
for building a container in a fluent style.hostPath
- the file system path on the hostcontainerPath
- the file system path inside the containermode
- the bind mode@Deprecated void addFileSystemBind(java.lang.String hostPath, java.lang.String containerPath, BindMode mode, SelinuxContext selinuxContext)
GenericContainer.withCopyToContainer(Transferable, String)
withFileSystemBind(String, String, BindMode)
for building a container in a fluent style.hostPath
- the file system path on the hostcontainerPath
- the file system path inside the containermode
- the bind modeselinuxContext
- selinux context argument to use for this file@Deprecated void addLink(LinkableContainer otherContainer, java.lang.String alias)
otherContainer
- the other container object to link toalias
- the alias (for the other container) that this container should be able to usevoid addExposedPort(java.lang.Integer port)
withExposedPorts(Integer...)
for building a container in a fluent style.port
- a TCP portvoid addExposedPorts(int... ports)
withExposedPorts(Integer...)
for building a container in a fluent style.ports
- an array of TCP portsSELF waitingFor(@NonNull @NonNull WaitStrategy waitStrategy)
WaitStrategy
to use to determine if the container is ready.waitStrategy
- the WaitStrategy to useWait.defaultWaitStrategy()
@Deprecated default SELF withFileSystemBind(java.lang.String hostPath, java.lang.String containerPath)
GenericContainer.withCopyToContainer(Transferable, String)
hostPath
- the file system path on the hostcontainerPath
- the file system path inside the container@Deprecated SELF withFileSystemBind(java.lang.String hostPath, java.lang.String containerPath, BindMode mode)
GenericContainer.withCopyToContainer(Transferable, String)
hostPath
- the file system path on the hostcontainerPath
- the file system path inside the containermode
- the bind modeSELF withVolumesFrom(Container container, BindMode mode)
container
- the container to add volumes frommode
- the bind modeSELF withExposedPorts(java.lang.Integer... ports)
ports
- an array of TCP ports@Deprecated SELF withCopyFileToContainer(MountableFile mountableFile, java.lang.String containerPath)
withCopyToContainer(Transferable, String)
insteadmountableFile
- a Mountable file with path of source file / folder on host machinecontainerPath
- a destination path on container to which the files / folders to be copiedSELF withCopyToContainer(Transferable transferable, java.lang.String containerPath)
transferable
- a TransferablecontainerPath
- a destination path on container to which the files / folders to be copiedSELF withEnv(java.lang.String key, java.lang.String value)
key
- environment variable keyvalue
- environment variable valuedefault SELF withEnv(java.lang.String key, java.util.function.Function<java.util.Optional<java.lang.String>,java.lang.String> mapper)
key
- environment variable keymapper
- environment variable value mapper, accepts old value as an argumentSELF withEnv(java.util.Map<java.lang.String,java.lang.String> env)
env
- map of environment variablesSELF withLabel(java.lang.String key, java.lang.String value)
key
- label keyvalue
- label valueSELF withLabels(java.util.Map<java.lang.String,java.lang.String> labels)
labels
- map of labelsSELF withCommand(java.lang.String cmd)
cmd
- a command in single string format (will automatically be split on spaces)SELF withCommand(java.lang.String... commandParts)
commandParts
- a command as an array of string partsSELF withExtraHost(java.lang.String hostname, java.lang.String ipAddress)
hostname
- hostname to use for this hosts file entryipAddress
- IP address to use for this hosts file entrySELF withNetworkMode(java.lang.String networkMode)
--net <name>
option on the docker CLI.networkMode
- network mode, e.g. including 'host', 'bridge', 'none' or the name of an existing named network.SELF withNetwork(Network network)
--network <name>
option on the docker CLI.network
- the instance of Network
SELF withNetworkAliases(java.lang.String... aliases)
--network-alias <my-service>
option on the docker CLI.aliases
- the list of aliasesSELF withImagePullPolicy(ImagePullPolicy policy)
@Deprecated default SELF withClasspathResourceMapping(java.lang.String resourcePath, java.lang.String containerPath, BindMode mode)
GenericContainer.withCopyToContainer(Transferable, String)
resourcePath
- path to the resource on the classpath (relative to the classpath root; should not start with a leading slash)containerPath
- path this should be mapped to inside the containermode
- access mode for the file@Deprecated SELF withClasspathResourceMapping(java.lang.String resourcePath, java.lang.String containerPath, BindMode mode, SelinuxContext selinuxContext)
GenericContainer.withCopyToContainer(Transferable, String)
resourcePath
- path to the resource on the classpath (relative to the classpath root; should not start with a leading slash)containerPath
- path this should be mapped to inside the containermode
- access mode for the fileselinuxContext
- selinux context argument to use for this fileSELF withStartupTimeout(java.time.Duration startupTimeout)
startupTimeout
- timeoutWaitStrategy.waitUntilReady(org.testcontainers.containers.wait.strategy.WaitStrategyTarget)
SELF withPrivilegedMode(boolean mode)
mode
- booleanSELF withMinimumRunningDuration(java.time.Duration minimumRunningDuration)
minimumRunningDuration
- duration this container should run for if started successfullySELF withStartupCheckStrategy(StartupCheckStrategy strategy)
strategy
- startup check strategySELF withWorkingDirectory(java.lang.String workDir)
workDir
- path to the working directory inside the containervoid setDockerImageName(@NonNull @NonNull java.lang.String dockerImageName)
dockerImageName
- image name@NonNull @NonNull java.lang.String getDockerImageName()
@Deprecated java.lang.String getTestHostIpAddress()
Testcontainers.exposeHostPorts(int...)
For example, if a web server is running on port 8080 on this local machine, the containerized web driver needs to be pointed at "http://" + getTestHostIpAddress() + ":8080" in order to access it. Trying to hit localhost from inside the container is not going to work, since the container has its own IP address.
default void followOutput(java.util.function.Consumer<OutputFrame> consumer)
consumer
- consumer that the frames should be sent todefault void followOutput(java.util.function.Consumer<OutputFrame> consumer, OutputFrame.OutputType... types)
consumer
- consumer that the frames should be sent totypes
- types that should be followed (one or both of STDOUT, STDERR)SELF withLogConsumer(java.util.function.Consumer<OutputFrame> consumer)
More than one consumer may be registered.
consumer
- consumer that output frames should be sent tojava.util.List<java.lang.String> getPortBindings()
getPortBindings
in interface ContainerState
java.util.List<java.lang.String> getExtraHosts()
java.util.concurrent.Future<java.lang.String> getImage()
@Deprecated java.util.List<java.lang.String> getEnv()
java.util.Map<java.lang.String,java.lang.String> getEnvMap()
java.lang.String[] getCommandParts()
java.util.List<com.github.dockerjava.api.model.Bind> getBinds()
@Deprecated java.util.Map<java.lang.String,LinkableContainer> getLinkedContainers()
void setExposedPorts(java.util.List<java.lang.Integer> exposedPorts)
void setPortBindings(java.util.List<java.lang.String> portBindings)
void setExtraHosts(java.util.List<java.lang.String> extraHosts)
void setImage(java.util.concurrent.Future<java.lang.String> image)
void setEnv(java.util.List<java.lang.String> env)
void setCommandParts(java.lang.String[] commandParts)
void setBinds(java.util.List<com.github.dockerjava.api.model.Bind> binds)
@Deprecated void setLinkedContainers(java.util.Map<java.lang.String,LinkableContainer> linkedContainers)
void setWaitStrategy(WaitStrategy waitStrategy)