public class DockerClient extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
CGROUP_MATCHER_PATTERN
Known cgroup formats
4:cpuset:/system.slice/docker-3dd988081e7149463c043b5d9c57d7309e079c5e9290f91feba1cc45a04d6a5b.scope
2:cpu:/docker/3dd988081e7149463c043b5d9c57d7309e079c5e9290f91feba1cc45a04d6a5b
|
static String |
DOCKER_DATE_TIME_FORMAT |
| Constructor and Description |
|---|
DockerClient(hudson.Launcher launcher,
hudson.model.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(hudson.EnvVars launchEnv,
String containerId) |
List<String> |
getVolumes(hudson.EnvVars launchEnv,
String containerID)
Inspect the mounts of a container.
|
String |
inspect(hudson.EnvVars launchEnv,
String objectId,
String fieldPath)
Inspect a docker image/container.
|
String |
inspectRequiredField(hudson.EnvVars launchEnv,
String objectId,
String fieldPath)
Inspect a docker image/container.
|
protected static hudson.util.VersionNumber |
parseVersionNumber(String versionString)
Parse a Docker version string (e.g.
|
void |
rm(hudson.EnvVars launchEnv,
String containerId)
Remove a container.
|
String |
run(hudson.EnvVars launchEnv,
String image,
String args,
String workdir,
Map<String,String> volumes,
Collection<String> volumesFromContainers,
hudson.EnvVars containerEnv,
String user,
String entrypoint)
Run a docker image.
|
void |
stop(hudson.EnvVars launchEnv,
String containerId)
Stop a container.
|
hudson.util.VersionNumber |
version()
Get the docker version.
|
String |
whoAmI()
Who is executing this
DockerClient instance. |
public static final String DOCKER_DATE_TIME_FORMAT
public static final String CGROUP_MATCHER_PATTERN
public DockerClient(@Nonnull hudson.Launcher launcher, @CheckForNull hudson.model.Node node, @CheckForNull String toolName)
public String run(@Nonnull hudson.EnvVars launchEnv, @Nonnull String image, @CheckForNull String args, @CheckForNull String workdir, @Nonnull Map<String,String> volumes, @Nonnull Collection<String> volumesFromContainers, @Nonnull hudson.EnvVars containerEnv, @Nonnull String user, @Nonnull String entrypoint) 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().entrypoint - The command to execute in the image container being run.IOExceptionInterruptedExceptionpublic void stop(@Nonnull hudson.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 hudson.EnvVars launchEnv, @Nonnull String containerId) throws IOException, InterruptedException
launchEnv - Docker client launch environment.containerId - The container ID.IOExceptionInterruptedException@CheckForNull public String inspect(@Nonnull hudson.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 hudson.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 hudson.util.VersionNumber version() throws IOException, InterruptedException
VersionNumber instance if the version string matches the expected format,
otherwise null.IOExceptionInterruptedExceptionprotected static hudson.util.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 hudson.EnvVars launchEnv, String containerId) throws IOException, InterruptedException
IOExceptionInterruptedExceptionpublic List<String> getVolumes(@Nonnull hudson.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. All rights reserved.