public interface Container<SELF extends Container<SELF>> extends LinkableContainer
Modifier and Type | Interface and Description |
---|---|
static class |
Container.ExecResult
Class to hold results from a "docker exec" command.
|
Modifier and Type | Method and Description |
---|---|
void |
addEnv(String key,
String value)
Add an environment variable to be passed to the container.
|
void |
addExposedPort(Integer port)
Add an exposed port.
|
void |
addExposedPorts(int... ports)
Add exposed ports.
|
void |
addFileSystemBind(String hostPath,
String containerPath,
BindMode mode)
Adds a file system binding.
|
void |
addLink(LinkableContainer otherContainer,
String alias)
Add a link to another container.
|
Container.ExecResult |
execInContainer(Charset outputCharset,
String... command)
Run a command inside a running container, as though using "docker exec".
|
Container.ExecResult |
execInContainer(String... command)
Run a command inside a running container, as though using "docker exec", and interpreting
the output as UTF8.
|
com.github.dockerjava.api.model.Info |
fetchDockerDaemonInfo() |
void |
followOutput(Consumer<OutputFrame> consumer)
Follow container output, sending each frame (usually, line) to a consumer.
|
void |
followOutput(Consumer<OutputFrame> consumer,
OutputFrame.OutputType... types)
Follow container output, sending each frame (usually, line) to a consumer.
|
List<com.github.dockerjava.api.model.Bind> |
getBinds() |
String[] |
getCommandParts() |
String |
getContainerId() |
com.github.dockerjava.api.command.InspectContainerResponse |
getContainerInfo() |
String |
getContainerIpAddress()
Get the IP address that this container may be reached on (may not be the local machine).
|
String |
getContainerName() |
com.github.dockerjava.api.DockerClient |
getDockerClient() |
com.github.dockerjava.api.model.Info |
getDockerDaemonInfo() |
String |
getDockerImageName()
Get image name.
|
List<String> |
getEnv() |
List<Integer> |
getExposedPorts() |
List<String> |
getExtraHosts() |
Future<String> |
getImage() |
Map<String,LinkableContainer> |
getLinkedContainers() |
Integer |
getMappedPort(int originalPort)
Get the actual mapped port for a given port exposed by the container.
|
List<String> |
getPortBindings() |
String |
getTestHostIpAddress()
Get the IP address that containers (e.g.
|
Boolean |
isRunning() |
default SELF |
self() |
void |
setBinds(List<com.github.dockerjava.api.model.Bind> binds) |
void |
setCommand(String... commandParts)
Set the command that should be run in the container.
|
void |
setCommand(String command)
Set the command that should be run in the container.
|
void |
setCommandParts(String[] commandParts) |
void |
setContainerId(String containerId)
Deprecated.
set by GenericContainer and should never be set outside
|
void |
setContainerInfo(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
Deprecated.
set by GenericContainer and should never be set outside
|
void |
setContainerName(String containerName)
Deprecated.
set by GenericContainer and should never be set outside
|
void |
setDockerClient(com.github.dockerjava.api.DockerClient dockerClient)
Deprecated.
set by GenericContainer and should never be set outside
|
void |
setDockerDaemonInfo(com.github.dockerjava.api.model.Info dockerDaemonInfo)
Deprecated.
set by GenericContainer and should never be set outside
|
void |
setDockerImageName(String dockerImageName)
Resolve Docker image and set it.
|
void |
setEnv(List<String> env) |
void |
setExposedPorts(List<Integer> exposedPorts) |
void |
setExtraHosts(List<String> extraHosts) |
void |
setImage(Future<String> image) |
void |
setLinkedContainers(Map<String,LinkableContainer> linkedContainers) |
void |
setPortBindings(List<String> portBindings) |
void |
setWaitStrategy(WaitStrategy waitStrategy) |
SELF |
waitingFor(WaitStrategy waitStrategy)
Specify the
WaitStrategy to use to determine if the container is ready. |
SELF |
withClasspathResourceMapping(String resourcePath,
String containerPath,
BindMode mode)
Map a resource (file or directory) on the classpath to a path inside the container.
|
SELF |
withCommand(String... commandParts)
Set the command that should be run in the container
|
SELF |
withCommand(String cmd)
Set the command that should be run in the container
|
SELF |
withEnv(Map<String,String> env)
Add environment variables to be passed to the container.
|
SELF |
withEnv(String key,
String value)
Add an environment variable to be passed to the container.
|
SELF |
withExposedPorts(Integer... ports)
Set the ports that this container listens on
|
SELF |
withExtraHost(String hostname,
String ipAddress)
Add an extra host entry to be passed to the container
|
SELF |
withFileSystemBind(String hostPath,
String containerPath,
BindMode mode)
Adds a file system binding.
|
SELF |
withLogConsumer(Consumer<OutputFrame> consumer)
Attach an output consumer at container startup, enabling stdout and stderr to be followed, waited on, etc.
|
SELF |
withMinimumRunningDuration(Duration minimumRunningDuration)
Only consider a container to have successfully started if it has been running for this duration.
|
SELF |
withNetworkMode(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(Duration startupTimeout)
Set the duration of waiting time until container treated as started.
|
SELF |
withVolumesFrom(Container container,
BindMode mode)
Adds container volumes.
|
SELF |
withWorkingDirectory(String workDir)
Set the working directory that the container should use on startup.
|
default SELF self()
void setCommand(@NonNull 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 String... commandParts)
withCommand(String...)
for building a container in a fluent style.commandParts
- a command as an array of string partsvoid addEnv(String key, String value)
withEnv(String, String)
for building a container in a fluent style.key
- environment variable keyvalue
- environment variable valuevoid addFileSystemBind(String hostPath, String containerPath, BindMode mode)
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 modevoid addLink(LinkableContainer otherContainer, 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(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 WaitStrategy waitStrategy)
WaitStrategy
to use to determine if the container is ready.waitStrategy
- the WaitStrategy to useWait.defaultWaitStrategy()
SELF withFileSystemBind(String hostPath, String containerPath, BindMode mode)
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(Integer... ports)
ports
- an array of TCP portsSELF withEnv(String key, String value)
key
- environment variable keyvalue
- environment variable valueSELF withEnv(Map<String,String> env)
env
- map of environment variablesSELF withCommand(String cmd)
cmd
- a command in single string format (will automatically be split on spaces)SELF withCommand(String... commandParts)
commandParts
- a command as an array of string partsSELF withExtraHost(String hostname, String ipAddress)
hostname
- hostname to use for this hosts file entryipAddress
- IP address to use for this hosts file entrySELF withNetworkMode(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 withClasspathResourceMapping(String resourcePath, String containerPath, BindMode mode)
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 fileSELF withStartupTimeout(Duration startupTimeout)
startupTimeout
- timeoutWaitStrategy.waitUntilReady(GenericContainer)
SELF withPrivilegedMode(boolean mode)
mode
- booleanString getContainerIpAddress()
SELF withMinimumRunningDuration(Duration minimumRunningDuration)
minimumRunningDuration
- duration this container should run for if started successfullySELF withStartupCheckStrategy(StartupCheckStrategy strategy)
strategy
- startup check strategySELF withWorkingDirectory(String workDir)
workDir
- path to the working directory inside the containerBoolean isRunning()
Integer getMappedPort(int originalPort)
originalPort
- the original TCP port that is exposedvoid setDockerImageName(@NonNull String dockerImageName)
dockerImageName
- image name@NonNull String getDockerImageName()
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.
void followOutput(Consumer<OutputFrame> consumer)
consumer
- consumer that the frames should be sent tovoid followOutput(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(Consumer<OutputFrame> consumer)
More than one consumer may be registered.
consumer
- consumer that output frames should be sent tocom.github.dockerjava.api.model.Info fetchDockerDaemonInfo() throws IOException
IOException
Container.ExecResult execInContainer(String... command) throws UnsupportedOperationException, IOException, InterruptedException
Container.ExecResult execInContainer(Charset outputCharset, String... command) throws UnsupportedOperationException, IOException, InterruptedException
This functionality is not available on a docker daemon running the older "lxc" execution driver. At the time of writing, CircleCI was using this driver.
outputCharset
- the character set used to interpret the output.command
- the parts of the command to runIOException
- if there's an issue communicating with DockerInterruptedException
- if the thread waiting for the response is interruptedUnsupportedOperationException
- if the docker daemon you're connecting to doesn't support "exec".String[] getCommandParts()
List<com.github.dockerjava.api.model.Bind> getBinds()
Map<String,LinkableContainer> getLinkedContainers()
com.github.dockerjava.api.DockerClient getDockerClient()
com.github.dockerjava.api.model.Info getDockerDaemonInfo()
String getContainerId()
String getContainerName()
getContainerName
in interface LinkableContainer
com.github.dockerjava.api.command.InspectContainerResponse getContainerInfo()
void setCommandParts(String[] commandParts)
void setBinds(List<com.github.dockerjava.api.model.Bind> binds)
void setLinkedContainers(Map<String,LinkableContainer> linkedContainers)
@Deprecated void setDockerClient(com.github.dockerjava.api.DockerClient dockerClient)
@Deprecated void setDockerDaemonInfo(com.github.dockerjava.api.model.Info dockerDaemonInfo)
@Deprecated void setContainerId(String containerId)
@Deprecated void setContainerName(String containerName)
void setWaitStrategy(WaitStrategy waitStrategy)
@Deprecated void setContainerInfo(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
Copyright © 2017. All rights reserved.