Improve container removal logic
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
parent
c39416707f
commit
65688954c9
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user