Skip to content

Commit

Permalink
Support filtering dangling networks (fixes #104)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmandalidis committed Dec 7, 2019
1 parent 14fdab4 commit 37bad51
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/mandas/docker/client/DockerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,16 @@ public static ListNetworksParam withType(final Network.Type type) {
return filter("type", type.getName());
}

/**
* Filter dagling networks.
* Networks not used by a container/service.
* @return The ListNetworksParam for the given type.
* @since Docker 19.03, API version 1.40
*/
public static ListNetworksParam dangling() {
return filter("dangling", "true");
}

/**
* Return built-in networks only.
* @return The ListNetworksParam for built-in networks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3616,6 +3616,11 @@ public void testFilterNetworks() throws Exception {
networks = sut.listNetworks(ListNetworksParam.withLabel("is-test", "false"));
assertThat(networks, not(hasItems(network1, network2)));

if (dockerApiVersionAtLeast("1.40")) {
networks = sut.listNetworks(ListNetworksParam.dangling());
assertThat(networks, hasItems(network1, network2));
}

sut.removeNetwork(network1.id());
sut.removeNetwork(network2.id());
}
Expand Down

0 comments on commit 37bad51

Please sign in to comment.