diff --git a/src/main/java/io/fabric8/maven/docker/StopMojo.java b/src/main/java/io/fabric8/maven/docker/StopMojo.java index 8ebe2b8d7..46218c780 100644 --- a/src/main/java/io/fabric8/maven/docker/StopMojo.java +++ b/src/main/java/io/fabric8/maven/docker/StopMojo.java @@ -126,21 +126,24 @@ private Set getNetworksToRemove(QueryService queryService, GavLabel gav for (ImageConfiguration image : getResolvedImages()) { final NetworkConfig config = image.getRunConfiguration().getNetworkingConfig(); + if (!config.isCustomNetwork() || config.getName() == null) { + continue; + } final Network network = getNetworkByName(networks, config.getCustomNetwork()); + if (network == null) { + continue; + } + customNetworks.add(network); + Collection existingContainers = + ContainerNamingUtil.getContainersToStop(image, + containerNamePattern, + getBuildTimestamp(), + queryService.getContainersForImage(image.getName(), false)); - if (config.isCustomNetwork() && network != null) { - customNetworks.add(network); - Collection existingContainers = - ContainerNamingUtil.getContainersToStop(image, - containerNamePattern, - getBuildTimestamp(), - queryService.getContainersForImage(image.getName(), false)); - - for (Container container : existingContainers) { - if (!shouldStopContainer(container, gavLabel)) { - // it's sill in use don't collect it - customNetworks.remove(network); - } + for (Container container : existingContainers) { + if (!shouldStopContainer(container, gavLabel)) { + // it's sill in use don't collect it + customNetworks.remove(network); } } }