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
FieldsModifier and TypeFieldDescriptionstatic intMaximum amount of time (in seconds) to wait fordockerclient operations which are supposed to be more or less instantaneous.static final Stringstatic booleanSkip removal of container after a container has been stopped. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.google.common.base.Optional<String>Checks if thisDockerClientinstance is running inside a container and returns the id of the container if so.org.jenkinsci.plugins.docker.commons.fingerprint.ContainerRecordgetContainerRecord(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 VersionNumberparseVersionNumber(String versionString) Parse a Docker version string (e.g.voidRemove 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.voidStop a container.version()Get the docker version.whoAmI()Who is executing thisDockerClientinstance.
-
Field Details
-
CLIENT_TIMEOUT
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static int CLIENT_TIMEOUTMaximum amount of time (in seconds) to wait fordockerclient 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 runcommand.workdir- The working directory in the container, ornullfor 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:
IOExceptionInterruptedException
-
listProcess
public List<String> listProcess(@NonNull EnvVars launchEnv, @NonNull String containerId) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
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:
IOExceptionInterruptedException
-
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:
IOExceptionInterruptedException
-
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:
IOExceptionInterruptedException
-
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
VersionNumberinstance if the version string matches the expected format, otherwisenull. - Throws:
IOExceptionInterruptedException
-
parseVersionNumber
Parse a Docker version string (e.g. "Docker version 1.5.0, build a8a31ef").- Parameters:
versionString- The version string to parse.- Returns:
- The
VersionNumberinstance if the version string matched the expected format, otherwisenull.
-
whoAmI
Who is executing thisDockerClientinstance.- Returns:
- a
Stringcontaining the uid:gid. - Throws:
IOExceptionInterruptedException
-
getContainerIdIfContainerized
public com.google.common.base.Optional<String> getContainerIdIfContainerized() throws IOException, InterruptedExceptionChecks if thisDockerClientinstance 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:
IOExceptionInterruptedException- See Also:
-
getContainerRecord
public org.jenkinsci.plugins.docker.commons.fingerprint.ContainerRecord getContainerRecord(@NonNull EnvVars launchEnv, String containerId) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
getVolumes
public List<String> getVolumes(@NonNull EnvVars launchEnv, String containerID) throws IOException, InterruptedException Inspect the mounts of a container. These might have been declaredVOLUMEs, 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
-