summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/net/libertacasa/pubsh/web/Docker.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/main/java/net/libertacasa/pubsh/web/Docker.java b/src/main/java/net/libertacasa/pubsh/web/Docker.java
index 637f22d..536a80e 100644
--- a/src/main/java/net/libertacasa/pubsh/web/Docker.java
+++ b/src/main/java/net/libertacasa/pubsh/web/Docker.java
@@ -1,9 +1,13 @@
package net.libertacasa.pubsh.web;
import java.time.Duration;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import com.github.dockerjava.api.DockerClient;
+import com.github.dockerjava.api.command.InspectExecResponse.Container;
+import com.github.dockerjava.api.command.ListContainersCmd;
import com.github.dockerjava.api.model.Image;
import com.github.dockerjava.core.DefaultDockerClientConfig;
import com.github.dockerjava.core.DockerClientConfig;
@@ -49,6 +53,27 @@ public class Docker {
}
public static void deleteContainer(String id) {
+ Collection<String> stringifiedId = Arrays.asList(id);
+ System.out.println(id);
+ System.out.println(stringifiedId);
+ List<com.github.dockerjava.api.model.Container> containerQuery = dockerClient.listContainersCmd().withShowAll(false).withIdFilter(stringifiedId).exec();
+ //apparently listContainersCmd returns a bunch of garbled crap, hence the less ideal toString/contains
+ if(! containerQuery.toString().contains(id)) {
+ System.out.println("Not found in running containers ...");
+ List<com.github.dockerjava.api.model.Container> containerQueryAll = dockerClient.listContainersCmd().withShowAll(true).withIdFilter(stringifiedId).exec();
+ if(containerQueryAll.toString().contains(id)) {
+ System.out.println("Found in stopped containers ...");
+ }
+ if(! containerQueryAll.toString().contains(id)) {
+ System.out.println("Not found at all. The fuck.");
+ }
+ }
+ if(containerQuery.toString().contains(id)) {
+ System.out.println("Found in running containers, stopping ...");
+ dockerClient.stopContainerCmd(id).exec();
+ }
+
+ //System.out.println(containerQuery);
dockerClient.removeContainerCmd(id).exec();
}