@@ -76,6 +76,13 @@ public class DockerClient {
7676 @ Restricted (NoExternalUse .class )
7777 public static int CLIENT_TIMEOUT = Integer .getInteger (DockerClient .class .getName () + ".CLIENT_TIMEOUT" , 180 ); // TODO 2.4+ SystemProperties
7878
79+ /**
80+ * Skip removal of container after a container has been stopped.
81+ */
82+ @ SuppressFBWarnings (value ="MS_SHOULD_BE_FINAL" , justification ="mutable for scripts" )
83+ @ Restricted (NoExternalUse .class )
84+ public static boolean SKIP_RM_ON_STOP = Boolean .getBoolean (DockerClient .class .getName () + ".SKIP_RM_ON_STOP" );
85+
7986 // e.g. 2015-04-09T13:40:21.981801679Z
8087 public static final String DOCKER_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss" ;
8188
@@ -165,7 +172,8 @@ public List<String> listProcess(@Nonnull EnvVars launchEnv, @Nonnull String cont
165172 * Stop a container.
166173 *
167174 * <p>
168- * Also removes ({@link #rm(EnvVars, String)}) the container.
175+ * Also removes ({@link #rm(EnvVars, String)}) the container if property
176+ * SKIP_RM_ON_STOP is unset or equals false.
169177 *
170178 * @param launchEnv Docker client launch environment.
171179 * @param containerId The container ID.
@@ -175,7 +183,9 @@ public void stop(@Nonnull EnvVars launchEnv, @Nonnull String containerId) throws
175183 if (result .getStatus () != 0 ) {
176184 throw new IOException (String .format ("Failed to kill container '%s'." , containerId ));
177185 }
178- rm (launchEnv , containerId );
186+ if (!SKIP_RM_ON_STOP ) {
187+ rm (launchEnv , containerId );
188+ }
179189 }
180190
181191 /**
0 commit comments