Browse Source

update DockerService

reghao 3 months ago
parent
commit
570b1c40f9

+ 9 - 2
common/src/main/java/cn/reghao/bnt/common/docker/DockerService.java

@@ -35,7 +35,11 @@ public class DockerService {
                 .collect(Collectors.groupingBy(InspectContainerResponse::getImageId));
         return docker.images().stream()
                 .map(image -> {
-                    String repoTag = image.getRepoTags().length > 0 ? image.getRepoTags()[0] : "<none>:<none>";
+                    String repoTag = "<none>:<none>";
+                    if (image.getRepoTags() != null && image.getRepoTags().length > 0) {
+                        repoTag = image.getRepoTags()[0];
+                    }
+
                     boolean matched = false;
                     if (keyword != null && !keyword.isBlank()) {
                         if (type == 1) {
@@ -78,7 +82,10 @@ public class DockerService {
                 log.error("container {}'s imageId {} not found" , inspectContainerResponse.getId(), imageId);
                 return null;
             }
-            String repoTag = image.getRepoTags().length > 0 ? image.getRepoTags()[0] : "<none>:<none>";
+            String repoTag = "<none>:<none>";
+            if (image.getRepoTags() != null && image.getRepoTags().length > 0) {
+                repoTag = image.getRepoTags()[0];
+            }
             return new DockerContainer(inspectContainerResponse, repoTag);
         }).filter(Objects::nonNull).collect(Collectors.toList());
     }