summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGeorg Pfuetzenreuter2022-05-06 15:25:14 +0200
committerGeorg Pfuetzenreuter2022-05-06 15:25:14 +0200
commit65688954c9f4a0393d58c695c12712707f47c527 (patch)
tree042bf7cfe99b8354a88fb1497a1b23e7040a6dde /src
parentc39416707f7253f1e41032fad5a7bc4dd3c17d38 (diff)
downloadpubsh-web-65688954c9f4a0393d58c695c12712707f47c527.tar.gz
pubsh-web-65688954c9f4a0393d58c695c12712707f47c527.tar.bz2
pubsh-web-65688954c9f4a0393d58c695c12712707f47c527.zip
Improve container removal logic
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
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();
}