Skip to content

Commit

Permalink
Add ability to skip removal of container after docker stop (#189)
Browse files Browse the repository at this point in the history
Co-authored-by: Jon Sten <jons@axis.com>
  • Loading branch information
jonsten and jonsten committed Aug 28, 2020
1 parent 04719f7 commit eb0b0db
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public class DockerClient {
@Restricted(NoExternalUse.class)
public static int CLIENT_TIMEOUT = Integer.getInteger(DockerClient.class.getName() + ".CLIENT_TIMEOUT", 180); // TODO 2.4+ SystemProperties

/**
* Skip removal of container after a container has been stopped.
*/
@SuppressFBWarnings(value="MS_SHOULD_BE_FINAL", justification="mutable for scripts")
@Restricted(NoExternalUse.class)
public static boolean SKIP_RM_ON_STOP = Boolean.getBoolean(DockerClient.class.getName() + ".SKIP_RM_ON_STOP");

// e.g. 2015-04-09T13:40:21.981801679Z
public static final String DOCKER_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";

Expand Down Expand Up @@ -165,7 +172,8 @@ public List<String> listProcess(@Nonnull EnvVars launchEnv, @Nonnull String cont
* Stop a container.
*
* <p>
* Also removes ({@link #rm(EnvVars, String)}) the container.
* Also removes ({@link #rm(EnvVars, String)}) the container if property
* SKIP_RM_ON_STOP is unset or equals false.
*
* @param launchEnv Docker client launch environment.
* @param containerId The container ID.
Expand All @@ -175,7 +183,9 @@ public void stop(@Nonnull EnvVars launchEnv, @Nonnull String containerId) throws
if (result.getStatus() != 0) {
throw new IOException(String.format("Failed to kill container '%s'.", containerId));
}
rm(launchEnv, containerId);
if (!SKIP_RM_ON_STOP) {
rm(launchEnv, containerId);
}
}

/**
Expand Down

0 comments on commit eb0b0db

Please sign in to comment.