public class DockerClient extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
CLIENT_TIMEOUT
Maximum amount of time (in seconds) to wait for
docker client operations which are supposed to be more or less instantaneous. |
static String |
DOCKER_DATE_TIME_FORMAT |
| Constructor and Description |
|---|
DockerClient(Launcher launcher,
Node node,
String toolName) |
| Modifier and Type | Method and Description |
|---|---|
com.google.common.base.Optional<String> |
getContainerIdIfContainerized()
Checks if this
DockerClient instance is running inside a container and returns the id of the container
if so. |
org.jenkinsci.plugins.docker.commons.fingerprint.ContainerRecord |
getContainerRecord(EnvVars launchEnv,
String containerId) |
List<String> |
getVolumes(EnvVars launchEnv,
String containerID)
Inspect the mounts of a container.
|
String |
inspect(EnvVars launchEnv,
String objectId,
String fieldPath)
Inspect a docker image/container.
|
String |
inspectRequiredField(EnvVars launchEnv,
String objectId,
String fieldPath)
Inspect a docker image/container.
|
List<String> |
listProcess(EnvVars launchEnv,
String containerId) |
protected static VersionNumber |
parseVersionNumber(String versionString)
Parse a Docker version string (e.g.
|
void |
rm(EnvVars launchEnv,
String containerId)
Remove a container.
|
String |
run(EnvVars launchEnv,
String image,
String args,
String workdir,
Map<String,String> volumes,
Collection<String> volumesFromContainers,
EnvVars containerEnv,
String user,
String... command)
Run a docker image.
|
void |
stop(EnvVars launchEnv,
String containerId)
Stop a container.
|
VersionNumber |
version()
Get the docker version.
|
String |
whoAmI()
Who is executing this
DockerClient instance. |
@Restricted(value=org.kohsuke.accmod.restrictions.NoExternalUse.class) public static int CLIENT_TIMEOUT
docker client operations which are supposed to be more or less instantaneous.public static final String DOCKER_DATE_TIME_FORMAT
public DockerClient(@Nonnull Launcher launcher, @CheckForNull Node node, @CheckForNull String toolName)
public String run(@Nonnull EnvVars launchEnv, @Nonnull String image, @CheckForNull String args, @CheckForNull String workdir, @Nonnull Map<String,String> volumes, @Nonnull Collection<String> volumesFromContainers, @Nonnull EnvVars containerEnv, @Nonnull String user, @Nonnull String... command) throws IOException, InterruptedException
launchEnv - Docker client launch environment.image - The image name.args - Any additional arguments for the docker run command.workdir - The working directory in the container, or null for default.volumes - Volumes to be bound. Supply an empty list if no volumes are to be bound.volumesFromContainers - Mounts all volumes from the given containers.containerEnv - Environment variables to set in container.user - The uid:gid to execute the container command as. Use whoAmI().command - The command to execute in the image container being run.IOExceptionInterruptedExceptionpublic List<String> listProcess(@Nonnull EnvVars launchEnv, @Nonnull String containerId) throws IOException, InterruptedException
IOExceptionInterruptedExceptionpublic void stop(@Nonnull EnvVars launchEnv, @Nonnull String containerId) throws IOException, InterruptedException
Also removes (rm(EnvVars, String)) the container.
launchEnv - Docker client launch environment.containerId - The container ID.IOExceptionInterruptedExceptionpublic void rm(@Nonnull EnvVars launchEnv, @Nonnull String containerId) throws IOException, InterruptedException
launchEnv - Docker client launch environment.containerId - The container ID.IOExceptionInterruptedException@CheckForNull public String inspect(@Nonnull EnvVars launchEnv, @Nonnull String objectId, @Nonnull String fieldPath) throws IOException, InterruptedException
launchEnv - Docker client launch environment.objectId - The image/container ID.fieldPath - The data path of the data required e.g. .NetworkSettings.IPAddress.IOExceptionInterruptedException@Nonnull public String inspectRequiredField(@Nonnull EnvVars launchEnv, @Nonnull String objectId, @Nonnull String fieldPath) throws IOException, InterruptedException
launchEnv - Docker client launch environment.objectId - The image/container ID.fieldPath - The data path of the data required e.g. .NetworkSettings.IPAddress.IOException - Execution error. Also fails if cannot retrieve the requested field from the requestInterruptedException - Interrupted@CheckForNull public VersionNumber version() throws IOException, InterruptedException
VersionNumber instance if the version string matches the expected format,
otherwise null.IOExceptionInterruptedExceptionprotected static VersionNumber parseVersionNumber(@Nonnull String versionString)
versionString - The version string to parse.VersionNumber instance if the version string matched the
expected format, otherwise null.public String whoAmI() throws IOException, InterruptedException
DockerClient instance.String containing the uid:gid.IOExceptionInterruptedExceptionpublic com.google.common.base.Optional<String> getContainerIdIfContainerized() throws IOException, InterruptedException
DockerClient instance is running inside a container and returns the id of the container
if so.IOExceptionInterruptedExceptionpublic org.jenkinsci.plugins.docker.commons.fingerprint.ContainerRecord getContainerRecord(@Nonnull EnvVars launchEnv, String containerId) throws IOException, InterruptedException
IOExceptionInterruptedExceptionpublic List<String> getVolumes(@Nonnull EnvVars launchEnv, String containerID) throws IOException, InterruptedException
VOLUMEs, or mounts defined via --volume.launchEnv - Docker client launch environment.containerID - The container ID.IOException - Execution error. Also fails if cannot retrieve the requested field from the requestInterruptedException - InterruptedCopyright © 2016–2019. All rights reserved.