Class DockerClient
java.lang.Object
org.jenkinsci.plugins.docker.workflow.client.DockerClient
- Direct Known Subclasses:
WindowsDockerClient
Simple docker client for Pipeline.
- Author:
- tom.fennelly@gmail.com
-
Field Summary
Modifier and TypeFieldDescriptionstatic int
Maximum amount of time (in seconds) to wait fordocker
client operations which are supposed to be more or less instantaneous.static final String
static boolean
Skip removal of container after a container has been stopped. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncom.google.common.base.Optional<String>
Checks if thisDockerClient
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) getVolumes
(EnvVars launchEnv, String containerID) Inspect the mounts of a container.Inspect a docker image/container.inspectRequiredField
(EnvVars launchEnv, String objectId, String fieldPath) Inspect a docker image/container.listProcess
(EnvVars launchEnv, String containerId) protected static VersionNumber
parseVersionNumber
(String versionString) Parse a Docker version string (e.g.void
Remove a container.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 a container.version()
Get the docker version.whoAmI()
Who is executing thisDockerClient
instance.
-
Field Details
-
CLIENT_TIMEOUT
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static int CLIENT_TIMEOUTMaximum amount of time (in seconds) to wait fordocker
client operations which are supposed to be more or less instantaneous. -
SKIP_RM_ON_STOP
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean SKIP_RM_ON_STOPSkip removal of container after a container has been stopped. -
DOCKER_DATE_TIME_FORMAT
- See Also:
-
-
Constructor Details
-
DockerClient
-
-
Method Details
-
run
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, InterruptedExceptionRun a docker image.- Parameters:
launchEnv
- Docker client launch environment.image
- The image name.args
- Any additional arguments for thedocker run
command.workdir
- The working directory in the container, ornull
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. UsewhoAmI()
.command
- The command to execute in the image container being run.- Returns:
- The container ID.
- Throws:
IOException
InterruptedException
-
listProcess
public List<String> listProcess(@NonNull EnvVars launchEnv, @NonNull String containerId) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
stop
public void stop(@NonNull EnvVars launchEnv, @NonNull String containerId) throws IOException, InterruptedException Stop a container.Also removes (
rm(EnvVars, String)
) the container if property SKIP_RM_ON_STOP is unset or equals false.- Parameters:
launchEnv
- Docker client launch environment.containerId
- The container ID.- Throws:
IOException
InterruptedException
-
rm
public void rm(@NonNull EnvVars launchEnv, @NonNull String containerId) throws IOException, InterruptedException Remove a container.- Parameters:
launchEnv
- Docker client launch environment.containerId
- The container ID.- Throws:
IOException
InterruptedException
-
inspect
@CheckForNull public String inspect(@NonNull EnvVars launchEnv, @NonNull String objectId, @NonNull String fieldPath) throws IOException, InterruptedException Inspect a docker image/container.- Parameters:
launchEnv
- Docker client launch environment.objectId
- The image/container ID.fieldPath
- The data path of the data required e.g..NetworkSettings.IPAddress
.- Returns:
- The inspected field value. Null if the command failed
- Throws:
IOException
InterruptedException
-
inspectRequiredField
@NonNull public String inspectRequiredField(@NonNull EnvVars launchEnv, @NonNull String objectId, @NonNull String fieldPath) throws IOException, InterruptedException Inspect a docker image/container.- Parameters:
launchEnv
- Docker client launch environment.objectId
- The image/container ID.fieldPath
- The data path of the data required e.g..NetworkSettings.IPAddress
.- Returns:
- The inspected field value. May be an empty string
- Throws:
IOException
- Execution error. Also fails if cannot retrieve the requested field from the requestInterruptedException
- Interrupted- Since:
- 1.1
-
version
Get the docker version.- Returns:
- The
VersionNumber
instance if the version string matches the expected format, otherwisenull
. - Throws:
IOException
InterruptedException
-
parseVersionNumber
Parse a Docker version string (e.g. "Docker version 1.5.0, build a8a31ef").- Parameters:
versionString
- The version string to parse.- Returns:
- The
VersionNumber
instance if the version string matched the expected format, otherwisenull
.
-
whoAmI
Who is executing thisDockerClient
instance.- Returns:
- a
String
containing the uid:gid. - Throws:
IOException
InterruptedException
-
getContainerIdIfContainerized
public com.google.common.base.Optional<String> getContainerIdIfContainerized() throws IOException, InterruptedExceptionChecks if thisDockerClient
instance is running inside a container and returns the id of the container if so.- Returns:
- an optional string containing the container id, or absent if it isn't containerized.
- Throws:
IOException
InterruptedException
- See Also:
-
getContainerRecord
public org.jenkinsci.plugins.docker.commons.fingerprint.ContainerRecord getContainerRecord(@NonNull EnvVars launchEnv, String containerId) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
getVolumes
public List<String> getVolumes(@NonNull EnvVars launchEnv, String containerID) throws IOException, InterruptedException Inspect the mounts of a container. These might have been declaredVOLUME
s, or mounts defined via--volume
.- Parameters:
launchEnv
- Docker client launch environment.containerID
- The container ID.- Returns:
- a list of filesystem paths inside the container
- Throws:
IOException
- Execution error. Also fails if cannot retrieve the requested field from the requestInterruptedException
- Interrupted
-