public class GenericContainer<SELF extends GenericContainer<SELF>> extends FailureDetectingExternalResource implements Container<SELF>, java.lang.AutoCloseable, WaitStrategyTarget, Startable
Modifier and Type | Class and Description |
---|---|
static class |
GenericContainer.AbstractWaitStrategy
Deprecated.
|
Container.ExecResult
Modifier and Type | Field and Description |
---|---|
static int |
CONTAINER_RUNNING_TIMEOUT_SEC |
protected java.lang.String |
containerId
Deprecated.
|
protected java.lang.String |
containerName
Deprecated.
|
protected java.util.Set<Startable> |
dependencies |
protected com.github.dockerjava.api.DockerClient |
dockerClient |
protected com.github.dockerjava.api.model.Info |
dockerDaemonInfo |
static java.lang.String |
INTERNAL_HOST_HOSTNAME |
protected WaitStrategy |
waitStrategy
The approach to determine if the container is ready.
|
STATE_HEALTHY
Constructor and Description |
---|
GenericContainer() |
GenericContainer(@NonNull java.util.concurrent.Future<java.lang.String> image) |
GenericContainer(@NonNull java.lang.String dockerImageName) |
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.
|
void |
addFileSystemBind(java.lang.String hostPath,
java.lang.String containerPath,
BindMode mode,
SelinuxContext selinuxContext)
Adds a file system binding.
|
protected void |
addFixedExposedPort(int hostPort,
int containerPort)
Add a TCP container port that should be bound to a fixed port on the docker host.
|
protected void |
addFixedExposedPort(int hostPort,
int containerPort,
InternetProtocol protocol)
Add a container port that should be bound to a fixed port on the docker host.
|
void |
addLink(LinkableContainer otherContainer,
java.lang.String alias)
|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description)
Deprecated.
|
protected void |
configure() |
protected void |
containerIsCreated(java.lang.String containerId) |
protected void |
containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse containerInfo) |
protected void |
containerIsStarting(com.github.dockerjava.api.command.InspectContainerResponse containerInfo) |
protected void |
containerIsStopped(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
A hook that is executed after the container is stopped with
stop() . |
protected void |
containerIsStopping(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
A hook that is executed before the container is stopped with
stop() . |
void |
copyFileFromContainer(java.lang.String containerPath,
java.lang.String destinationPath)
Copies a file which resides inside the container to user defined directory
|
<T> T |
copyFileFromContainer(java.lang.String containerPath,
ThrowingFunction<java.io.InputStream,T> consumer)
Streams a file which resides inside the container
|
void |
copyFileToContainer(MountableFile mountableFile,
java.lang.String containerPath)
Copies a file or directory to the container.
|
void |
copyFileToContainer(Transferable transferable,
java.lang.String containerPath)
Copies a file to the container.
|
protected java.nio.file.Path |
createVolumeDirectory(boolean temporary)
Creates a directory on the local filesystem which will be mounted as a volume for the container.
|
SELF |
dependsOn(java.util.List<Startable> startables)
Delays this container's creation and start until provided
Startable s start first. |
SELF |
dependsOn(Startable... startables) |
protected void |
doStart() |
boolean |
equals(java.lang.Object o) |
Container.ExecResult |
execInContainer(java.nio.charset.Charset outputCharset,
java.lang.String... command)
Run a command inside a running container, as though using "docker exec".
|
Container.ExecResult |
execInContainer(java.lang.String... command)
Run a command inside a running container, as though using "docker exec", and interpreting
the output as UTF8.
|
protected void |
failed(java.lang.Throwable e,
org.junit.runner.Description description)
Deprecated.
|
com.github.dockerjava.api.model.Info |
fetchDockerDaemonInfo() |
protected void |
finished(org.junit.runner.Description description)
Deprecated.
|
@NonNull java.util.List<com.github.dockerjava.api.model.Bind> |
getBinds() |
@NonNull java.lang.String[] |
getCommandParts() |
java.lang.String |
getContainerId() |
com.github.dockerjava.api.command.InspectContainerResponse |
getContainerInfo() |
java.lang.String |
getContainerName()
Deprecated.
|
java.util.Map<MountableFile,java.lang.String> |
getCopyToFileContainerPathMap() |
java.util.Set<java.util.function.Consumer<com.github.dockerjava.api.command.CreateContainerCmd>> |
getCreateContainerCmdModifiers() |
java.util.Set<Startable> |
getDependencies() |
com.github.dockerjava.api.DockerClient |
getDockerClient() |
com.github.dockerjava.api.model.Info |
getDockerDaemonInfo() |
@NonNull java.lang.String |
getDockerImageName()
Get image name.
|
java.util.List<java.lang.String> |
getEnv() |
java.util.Map<java.lang.String,java.lang.String> |
getEnvMap() |
@NonNull java.util.List<java.lang.Integer> |
getExposedPorts() |
@NonNull java.util.List<java.lang.String> |
getExtraHosts() |
@NonNull java.util.concurrent.Future<java.lang.String> |
getImage() |
java.lang.String |
getIpAddress()
Deprecated.
please use getContainerIpAddress() instead
|
@NonNull java.util.Map<java.lang.String,java.lang.String> |
getLabels() |
@NonNull java.util.Map<java.lang.String,LinkableContainer> |
getLinkedContainers()
|
protected java.lang.Integer |
getLivenessCheckPort()
Deprecated.
see
getLivenessCheckPorts() for replacement |
java.util.Set<java.lang.Integer> |
getLivenessCheckPortNumbers() |
protected @NotNull @NonNull java.util.Set<java.lang.Integer> |
getLivenessCheckPorts()
Deprecated.
use
getLivenessCheckPortNumbers() instead |
java.util.List<java.util.function.Consumer<OutputFrame>> |
getLogConsumers() |
@NonNull Network |
getNetwork() |
@NonNull java.util.List<java.lang.String> |
getNetworkAliases() |
@NonNull java.lang.String |
getNetworkMode() |
@NonNull java.util.List<java.lang.String> |
getPortBindings() |
@Nullable java.lang.Long |
getShmSize()
The shared memory size to use when starting the container.
|
int |
getStartupAttempts() |
StartupCheckStrategy |
getStartupCheckStrategy() |
java.lang.String |
getTestHostIpAddress()
Get the IP address that containers (e.g.
|
@Nullable java.util.Map<java.lang.String,java.lang.String> |
getTmpFsMapping() |
@NonNull java.util.List<com.github.dockerjava.api.model.VolumesFrom> |
getVolumesFroms() |
protected WaitStrategy |
getWaitStrategy()
The
WaitStrategy to use to determine if the container is ready. |
@Nullable java.lang.String |
getWorkingDirectory() |
int |
hashCode() |
boolean |
isPrivilegedMode() |
protected org.slf4j.Logger |
logger()
Provide a logger that references the docker image name.
|
void |
setBinds(@NonNull 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(@NonNull java.lang.String[] commandParts) |
void |
setCopyToFileContainerPathMap(java.util.Map<MountableFile,java.lang.String> copyToFileContainerPathMap) |
void |
setDockerImageName(@NonNull java.lang.String dockerImageName)
Resolve Docker image and set it.
|
void |
setEnv(java.util.List<java.lang.String> env) |
void |
setExposedPorts(@NonNull java.util.List<java.lang.Integer> exposedPorts) |
void |
setExtraHosts(@NonNull java.util.List<java.lang.String> extraHosts) |
void |
setImage(@NonNull java.util.concurrent.Future<java.lang.String> image) |
void |
setLabels(@NonNull java.util.Map<java.lang.String,java.lang.String> labels) |
void |
setLinkedContainers(@NonNull java.util.Map<java.lang.String,LinkableContainer> linkedContainers)
|
void |
setLogConsumers(java.util.List<java.util.function.Consumer<OutputFrame>> logConsumers) |
void |
setNetwork(@NonNull Network network) |
void |
setNetworkAliases(@NonNull java.util.List<java.lang.String> networkAliases) |
void |
setNetworkMode(@NonNull java.lang.String networkMode) |
void |
setPortBindings(@NonNull java.util.List<java.lang.String> portBindings) |
void |
setPrivilegedMode(boolean privilegedMode) |
void |
setShmSize(@Nullable java.lang.Long shmSize)
The shared memory size to use when starting the container.
|
void |
setStartupAttempts(int startupAttempts) |
void |
setStartupCheckStrategy(StartupCheckStrategy startupCheckStrategy) |
void |
setTmpFsMapping(@Nullable java.util.Map<java.lang.String,java.lang.String> tmpFsMapping) |
void |
setVolumesFroms(@NonNull java.util.List<com.github.dockerjava.api.model.VolumesFrom> volumesFroms) |
void |
setWaitStrategy(WaitStrategy waitStrategy) |
void |
setWorkingDirectory(@Nullable java.lang.String workingDirectory) |
void |
start()
Starts the container using docker, pulling an image if necessary.
|
protected void |
starting(org.junit.runner.Description description)
Deprecated.
|
void |
stop()
Stops the container.
|
protected void |
succeeded(org.junit.runner.Description description)
Deprecated.
|
java.lang.String |
toString() |
SELF |
waitingFor(WaitStrategy waitStrategy)
Specify the
WaitStrategy to use to determine if the container is ready. |
protected void |
waitUntilContainerStarted()
Wait until the container has started.
|
SELF |
withClasspathResourceMapping(java.lang.String resourcePath,
java.lang.String containerPath,
BindMode mode)
Map a resource (file or directory) on the classpath to a path inside the container.
|
SELF |
withClasspathResourceMapping(java.lang.String resourcePath,
java.lang.String containerPath,
BindMode mode,
SelinuxContext selinuxContext)
Map a resource (file or directory) on the classpath to a path inside the container.
|
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)
Set the file to be copied before starting a created container
|
SELF |
withCreateContainerCmdModifier(java.util.function.Consumer<com.github.dockerjava.api.command.CreateContainerCmd> modifier)
Allow low level modifications of
CreateContainerCmd after it was pre-configured in tryStart() . |
SELF |
withEnv(java.util.Map<java.lang.String,java.lang.String> env)
Add environment variables 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
|
SELF |
withFileSystemBind(java.lang.String hostPath,
java.lang.String containerPath,
BindMode mode)
Adds a file system binding.
|
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 |
withSharedMemorySize(java.lang.Long bytes)
Size of /dev/shm
|
SELF |
withStartupAttempts(int attempts)
Allow container startup to be attempted more than once if an error occurs.
|
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 |
withTmpFs(java.util.Map<java.lang.String,java.lang.String> mapping)
First class support for configuring tmpfs
|
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.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBind
getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunning
public static final int CONTAINER_RUNNING_TIMEOUT_SEC
public static final java.lang.String INTERNAL_HOST_HOSTNAME
protected final java.util.Set<Startable> dependencies
protected com.github.dockerjava.api.DockerClient dockerClient
protected com.github.dockerjava.api.model.Info dockerDaemonInfo
@Deprecated protected java.lang.String containerId
ContainerState.getContainerId()
@Deprecated protected java.lang.String containerName
getContainerInfo()
@NonNull protected WaitStrategy waitStrategy
public GenericContainer()
public GenericContainer(@NonNull @NonNull java.lang.String dockerImageName)
public GenericContainer(@NonNull @NonNull java.util.concurrent.Future<java.lang.String> image)
public SELF dependsOn(Startable... startables)
dependsOn(List)
public SELF dependsOn(java.util.List<Startable> startables)
Startable
s start first.
Note that the circular dependencies are not supported.startables
- a list of Startable
to depend onStartables.deepStart(Collection)
public java.lang.String getContainerId()
getContainerId
in interface ContainerState
public void start()
protected void doStart()
protected org.slf4j.Logger logger()
protected java.nio.file.Path createVolumeDirectory(boolean temporary)
temporary
- is the volume directory temporary? If true, the directory will be deleted on JVM shutdown.protected void configure()
protected void containerIsCreated(java.lang.String containerId)
protected void containerIsStarting(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
protected void containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
protected void containerIsStopping(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
stop()
.
Warning! This hook won't be executed if the container is terminated during
the JVM's shutdown hook or by Ryuk.protected void containerIsStopped(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
stop()
.
Warning! This hook won't be executed if the container is terminated during
the JVM's shutdown hook or by Ryuk.@Deprecated protected java.lang.Integer getLivenessCheckPort()
getLivenessCheckPorts()
for replacement@NotNull @NonNull @Deprecated protected @NotNull @NonNull java.util.Set<java.lang.Integer> getLivenessCheckPorts()
getLivenessCheckPortNumbers()
insteadpublic java.util.Set<java.lang.Integer> getLivenessCheckPortNumbers()
getLivenessCheckPortNumbers
in interface WaitStrategyTarget
public SELF waitingFor(@NonNull WaitStrategy waitStrategy)
WaitStrategy
to use to determine if the container is ready.waitingFor
in interface Container<SELF extends GenericContainer<SELF>>
waitStrategy
- the WaitStrategy to useWait.defaultWaitStrategy()
protected WaitStrategy getWaitStrategy()
WaitStrategy
to use to determine if the container is ready.
Defaults to Wait.defaultWaitStrategy()
.WaitStrategy
to usepublic void setWaitStrategy(WaitStrategy waitStrategy)
setWaitStrategy
in interface Container<SELF extends GenericContainer<SELF>>
protected void waitUntilContainerStarted()
WaitStrategy
public void setCommand(@NonNull @NonNull java.lang.String command)
Container.withCommand(String)
for building a container in a fluent style.setCommand
in interface Container<SELF extends GenericContainer<SELF>>
command
- a command in single string format (will automatically be split on spaces)public void setCommand(@NonNull java.lang.String... commandParts)
Container.withCommand(String...)
for building a container in a fluent style.setCommand
in interface Container<SELF extends GenericContainer<SELF>>
commandParts
- a command as an array of string partspublic java.util.Map<java.lang.String,java.lang.String> getEnvMap()
getEnvMap
in interface Container<SELF extends GenericContainer<SELF>>
public java.util.List<java.lang.String> getEnv()
getEnv
in interface Container<SELF extends GenericContainer<SELF>>
public void setEnv(java.util.List<java.lang.String> env)
setEnv
in interface Container<SELF extends GenericContainer<SELF>>
public void addEnv(java.lang.String key, java.lang.String value)
Container.withEnv(String, String)
for building a container in a fluent style.addEnv
in interface Container<SELF extends GenericContainer<SELF>>
key
- environment variable keyvalue
- environment variable valuepublic void addFileSystemBind(java.lang.String hostPath, java.lang.String containerPath, BindMode mode, SelinuxContext selinuxContext)
Container.withFileSystemBind(String, String, BindMode)
for building a container in a fluent style.addFileSystemBind
in interface Container<SELF extends GenericContainer<SELF>>
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 filepublic SELF withFileSystemBind(java.lang.String hostPath, java.lang.String containerPath, BindMode mode)
withFileSystemBind
in interface Container<SELF extends GenericContainer<SELF>>
hostPath
- the file system path on the hostcontainerPath
- the file system path inside the containermode
- the bind modepublic SELF withVolumesFrom(Container container, BindMode mode)
withVolumesFrom
in interface Container<SELF extends GenericContainer<SELF>>
container
- the container to add volumes frommode
- the bind mode@Deprecated public void addLink(LinkableContainer otherContainer, java.lang.String alias)
Container
addLink
in interface Container<SELF extends GenericContainer<SELF>>
otherContainer
- the other container object to link toalias
- the alias (for the other container) that this container should be able to usepublic void addExposedPort(java.lang.Integer port)
Container
Container.withExposedPorts(Integer...)
for building a container in a fluent style.addExposedPort
in interface Container<SELF extends GenericContainer<SELF>>
port
- a TCP portpublic void addExposedPorts(int... ports)
Container
Container.withExposedPorts(Integer...)
for building a container in a fluent style.addExposedPorts
in interface Container<SELF extends GenericContainer<SELF>>
ports
- an array of TCP ports@Deprecated public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
apply
in interface org.junit.rules.TestRule
apply
in class FailureDetectingExternalResource
@Deprecated protected void starting(org.junit.runner.Description description)
starting
in class FailureDetectingExternalResource
@Deprecated protected void succeeded(org.junit.runner.Description description)
succeeded
in class FailureDetectingExternalResource
@Deprecated protected void failed(java.lang.Throwable e, org.junit.runner.Description description)
failed
in class FailureDetectingExternalResource
@Deprecated protected void finished(org.junit.runner.Description description)
finished
in class FailureDetectingExternalResource
public SELF withExposedPorts(java.lang.Integer... ports)
withExposedPorts
in interface Container<SELF extends GenericContainer<SELF>>
ports
- an array of TCP portsprotected void addFixedExposedPort(int hostPort, int containerPort)
Note that this method is protected scope to discourage use, as clashes or instability are more likely when
using fixed port mappings. If you need to use this method from a test, please use FixedHostPortGenericContainer
instead of GenericContainer.
hostPort
- containerPort
- protected void addFixedExposedPort(int hostPort, int containerPort, InternetProtocol protocol)
Note that this method is protected scope to discourage use, as clashes or instability are more likely when
using fixed port mappings. If you need to use this method from a test, please use FixedHostPortGenericContainer
instead of GenericContainer.
hostPort
- containerPort
- protocol
- public SELF withEnv(java.lang.String key, java.lang.String value)
withEnv
in interface Container<SELF extends GenericContainer<SELF>>
key
- environment variable keyvalue
- environment variable valuepublic SELF withEnv(java.util.Map<java.lang.String,java.lang.String> env)
withEnv
in interface Container<SELF extends GenericContainer<SELF>>
env
- map of environment variablespublic SELF withLabel(java.lang.String key, java.lang.String value)
withLabel
in interface Container<SELF extends GenericContainer<SELF>>
key
- label keyvalue
- label valuepublic SELF withLabels(java.util.Map<java.lang.String,java.lang.String> labels)
withLabels
in interface Container<SELF extends GenericContainer<SELF>>
labels
- map of labelspublic SELF withCommand(java.lang.String cmd)
withCommand
in interface Container<SELF extends GenericContainer<SELF>>
cmd
- a command in single string format (will automatically be split on spaces)public SELF withCommand(java.lang.String... commandParts)
withCommand
in interface Container<SELF extends GenericContainer<SELF>>
commandParts
- a command as an array of string partspublic SELF withExtraHost(java.lang.String hostname, java.lang.String ipAddress)
withExtraHost
in interface Container<SELF extends GenericContainer<SELF>>
hostname
- hostname to use for this hosts file entryipAddress
- IP address to use for this hosts file entrypublic SELF withNetworkMode(java.lang.String networkMode)
Container
--net <name>
option on the docker CLI.withNetworkMode
in interface Container<SELF extends GenericContainer<SELF>>
networkMode
- network mode, e.g. including 'host', 'bridge', 'none' or the name of an existing named network.public SELF withNetwork(Network network)
Container
--network <name>
option on the docker CLI.withNetwork
in interface Container<SELF extends GenericContainer<SELF>>
network
- the instance of Network
public SELF withNetworkAliases(java.lang.String... aliases)
Container
--network-alias <my-service>
option on the docker CLI.withNetworkAliases
in interface Container<SELF extends GenericContainer<SELF>>
aliases
- the list of aliasespublic SELF withClasspathResourceMapping(java.lang.String resourcePath, java.lang.String containerPath, BindMode mode)
withClasspathResourceMapping
in interface Container<SELF extends GenericContainer<SELF>>
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 filepublic SELF withClasspathResourceMapping(java.lang.String resourcePath, java.lang.String containerPath, BindMode mode, SelinuxContext selinuxContext)
withClasspathResourceMapping
in interface Container<SELF extends GenericContainer<SELF>>
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 filepublic SELF withStartupTimeout(java.time.Duration startupTimeout)
withStartupTimeout
in interface Container<SELF extends GenericContainer<SELF>>
startupTimeout
- timeoutWaitStrategy.waitUntilReady(org.testcontainers.containers.wait.strategy.WaitStrategyTarget)
public SELF withPrivilegedMode(boolean mode)
Container
withPrivilegedMode
in interface Container<SELF extends GenericContainer<SELF>>
mode
- booleanpublic SELF withMinimumRunningDuration(java.time.Duration minimumRunningDuration)
withMinimumRunningDuration
in interface Container<SELF extends GenericContainer<SELF>>
minimumRunningDuration
- duration this container should run for if started successfullypublic SELF withStartupCheckStrategy(StartupCheckStrategy strategy)
withStartupCheckStrategy
in interface Container<SELF extends GenericContainer<SELF>>
strategy
- startup check strategypublic SELF withWorkingDirectory(java.lang.String workDir)
withWorkingDirectory
in interface Container<SELF extends GenericContainer<SELF>>
workDir
- path to the working directory inside the containerpublic SELF withCopyFileToContainer(MountableFile mountableFile, java.lang.String containerPath)
withCopyFileToContainer
in interface Container<SELF extends GenericContainer<SELF>>
mountableFile
- a Mountable file with path of source file / folder on host machinecontainerPath
- a destination path on conatiner to which the files / folders to be copied@Deprecated public java.lang.String getIpAddress()
public void setDockerImageName(@NonNull @NonNull java.lang.String dockerImageName)
setDockerImageName
in interface Container<SELF extends GenericContainer<SELF>>
dockerImageName
- image name@NonNull public @NonNull java.lang.String getDockerImageName()
getDockerImageName
in interface Container<SELF extends GenericContainer<SELF>>
public java.lang.String getTestHostIpAddress()
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.
getTestHostIpAddress
in interface Container<SELF extends GenericContainer<SELF>>
public SELF withLogConsumer(java.util.function.Consumer<OutputFrame> consumer)
More than one consumer may be registered.
withLogConsumer
in interface Container<SELF extends GenericContainer<SELF>>
consumer
- consumer that output frames should be sent topublic com.github.dockerjava.api.model.Info fetchDockerDaemonInfo() throws java.io.IOException
fetchDockerDaemonInfo
in interface Container<SELF extends GenericContainer<SELF>>
java.io.IOException
public Container.ExecResult execInContainer(java.lang.String... command) throws java.lang.UnsupportedOperationException, java.io.IOException, java.lang.InterruptedException
execInContainer
in interface Container<SELF extends GenericContainer<SELF>>
java.lang.UnsupportedOperationException
java.io.IOException
java.lang.InterruptedException
ExecInContainerPattern.execInContainer(com.github.dockerjava.api.command.InspectContainerResponse, String...)
public void copyFileToContainer(MountableFile mountableFile, java.lang.String containerPath)
copyFileToContainer
in interface Container<SELF extends GenericContainer<SELF>>
mountableFile
- file or directory which is copied into the containercontainerPath
- destination path inside the containerpublic void copyFileToContainer(Transferable transferable, java.lang.String containerPath)
Container
copyFileToContainer
in interface Container<SELF extends GenericContainer<SELF>>
transferable
- file which is copied into the containercontainerPath
- destination path inside the containerpublic void copyFileFromContainer(java.lang.String containerPath, java.lang.String destinationPath)
copyFileFromContainer
in interface Container<SELF extends GenericContainer<SELF>>
containerPath
- path to file which is copied from containerdestinationPath
- destination path to which file is copied with file namepublic <T> T copyFileFromContainer(java.lang.String containerPath, ThrowingFunction<java.io.InputStream,T> consumer)
Container
copyFileFromContainer
in interface Container<SELF extends GenericContainer<SELF>>
containerPath
- path to file which is copied from containerconsumer
- function that takes InputStream of the copied filepublic Container.ExecResult execInContainer(java.nio.charset.Charset outputCharset, java.lang.String... command) throws java.lang.UnsupportedOperationException, java.io.IOException, java.lang.InterruptedException
execInContainer
in interface Container<SELF extends GenericContainer<SELF>>
java.lang.UnsupportedOperationException
java.io.IOException
java.lang.InterruptedException
ExecInContainerPattern.execInContainer(com.github.dockerjava.api.command.InspectContainerResponse, Charset, String...)
public SELF withStartupAttempts(int attempts)
attempts
- number of attemptspublic SELF withCreateContainerCmdModifier(java.util.function.Consumer<com.github.dockerjava.api.command.CreateContainerCmd> modifier)
CreateContainerCmd
after it was pre-configured in tryStart()
.
Invocation happens eagerly on a moment when container is created.
Warning: this does expose the underlying docker-java API so might change outside of our control.modifier
- Consumer
of CreateContainerCmd
.public SELF withSharedMemorySize(java.lang.Long bytes)
bytes
- The number of bytes to assign the shared memory. If null, it will apply the Docker default which is 64 MB.public SELF withTmpFs(java.util.Map<java.lang.String,java.lang.String> mapping)
mapping
- path and params of tmpfs/mount flag for containerpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
@NonNull public @NonNull java.util.List<java.lang.Integer> getExposedPorts()
getExposedPorts
in interface ContainerState
@NonNull public @NonNull java.util.List<java.lang.String> getPortBindings()
getPortBindings
in interface Container<SELF extends GenericContainer<SELF>>
getPortBindings
in interface ContainerState
@NonNull public @NonNull java.util.List<java.lang.String> getExtraHosts()
getExtraHosts
in interface Container<SELF extends GenericContainer<SELF>>
@NonNull public @NonNull java.lang.String getNetworkMode()
@NonNull public @NonNull Network getNetwork()
@NonNull public @NonNull java.util.List<java.lang.String> getNetworkAliases()
@NonNull public @NonNull java.util.concurrent.Future<java.lang.String> getImage()
getImage
in interface Container<SELF extends GenericContainer<SELF>>
@NonNull public @NonNull java.util.Map<java.lang.String,java.lang.String> getLabels()
@NonNull public @NonNull java.lang.String[] getCommandParts()
getCommandParts
in interface Container<SELF extends GenericContainer<SELF>>
@NonNull public @NonNull java.util.List<com.github.dockerjava.api.model.Bind> getBinds()
getBinds
in interface Container<SELF extends GenericContainer<SELF>>
public boolean isPrivilegedMode()
@NonNull public @NonNull java.util.List<com.github.dockerjava.api.model.VolumesFrom> getVolumesFroms()
@Deprecated @NonNull public @NonNull java.util.Map<java.lang.String,LinkableContainer> getLinkedContainers()
getLinkedContainers
in interface Container<SELF extends GenericContainer<SELF>>
public StartupCheckStrategy getStartupCheckStrategy()
public int getStartupAttempts()
@Nullable public @Nullable java.lang.String getWorkingDirectory()
@Nullable public @Nullable java.lang.Long getShmSize()
public java.util.Map<MountableFile,java.lang.String> getCopyToFileContainerPathMap()
public java.util.Set<Startable> getDependencies()
getDependencies
in interface Startable
public com.github.dockerjava.api.DockerClient getDockerClient()
getDockerClient
in interface Container<SELF extends GenericContainer<SELF>>
public com.github.dockerjava.api.model.Info getDockerDaemonInfo()
getDockerDaemonInfo
in interface Container<SELF extends GenericContainer<SELF>>
@Deprecated public java.lang.String getContainerName()
getContainerInfo()
getContainerName
in interface LinkableContainer
public com.github.dockerjava.api.command.InspectContainerResponse getContainerInfo()
getContainerInfo
in interface ContainerState
public java.util.List<java.util.function.Consumer<OutputFrame>> getLogConsumers()
public java.util.Set<java.util.function.Consumer<com.github.dockerjava.api.command.CreateContainerCmd>> getCreateContainerCmdModifiers()
@Nullable public @Nullable java.util.Map<java.lang.String,java.lang.String> getTmpFsMapping()
public void setExposedPorts(@NonNull @NonNull java.util.List<java.lang.Integer> exposedPorts)
setExposedPorts
in interface Container<SELF extends GenericContainer<SELF>>
public void setPortBindings(@NonNull @NonNull java.util.List<java.lang.String> portBindings)
setPortBindings
in interface Container<SELF extends GenericContainer<SELF>>
public void setExtraHosts(@NonNull @NonNull java.util.List<java.lang.String> extraHosts)
setExtraHosts
in interface Container<SELF extends GenericContainer<SELF>>
public void setNetworkMode(@NonNull @NonNull java.lang.String networkMode)
public void setNetwork(@NonNull @NonNull Network network)
public void setNetworkAliases(@NonNull @NonNull java.util.List<java.lang.String> networkAliases)
public void setImage(@NonNull @NonNull java.util.concurrent.Future<java.lang.String> image)
setImage
in interface Container<SELF extends GenericContainer<SELF>>
public void setLabels(@NonNull @NonNull java.util.Map<java.lang.String,java.lang.String> labels)
public void setCommandParts(@NonNull @NonNull java.lang.String[] commandParts)
setCommandParts
in interface Container<SELF extends GenericContainer<SELF>>
public void setBinds(@NonNull @NonNull java.util.List<com.github.dockerjava.api.model.Bind> binds)
setBinds
in interface Container<SELF extends GenericContainer<SELF>>
public void setPrivilegedMode(boolean privilegedMode)
public void setVolumesFroms(@NonNull @NonNull java.util.List<com.github.dockerjava.api.model.VolumesFrom> volumesFroms)
@Deprecated public void setLinkedContainers(@NonNull @NonNull java.util.Map<java.lang.String,LinkableContainer> linkedContainers)
setLinkedContainers
in interface Container<SELF extends GenericContainer<SELF>>
public void setStartupCheckStrategy(StartupCheckStrategy startupCheckStrategy)
public void setStartupAttempts(int startupAttempts)
public void setWorkingDirectory(@Nullable @Nullable java.lang.String workingDirectory)
public void setShmSize(@Nullable @Nullable java.lang.Long shmSize)
public void setCopyToFileContainerPathMap(java.util.Map<MountableFile,java.lang.String> copyToFileContainerPathMap)
public void setLogConsumers(java.util.List<java.util.function.Consumer<OutputFrame>> logConsumers)
public void setTmpFsMapping(@Nullable @Nullable java.util.Map<java.lang.String,java.lang.String> tmpFsMapping)
public java.lang.String toString()
toString
in class java.lang.Object