use of com.github.dockerjava.api.model.Network in project tutorials by eugenp.
the class NetworkLiveTest method whenInspectingNetwork_thenSizeMustBeGreaterThanZero.
@Test
public void whenInspectingNetwork_thenSizeMustBeGreaterThanZero() {
// when
String networkName = "bridge";
Network network = dockerClient.inspectNetworkCmd().withNetworkId(networkName).exec();
// then
assertThat(network.getName(), is(networkName));
}
use of com.github.dockerjava.api.model.Network in project testcontainers-java by testcontainers.
the class ResourceReaper method removeNetwork.
private void removeNetwork(String id) {
try {
List<Network> networks;
try {
// Try to find the network if it still exists
// Listing by ID first prevents docker-java logging an error if we just go blindly into removeNetworkCmd
networks = dockerClient.listNetworksCmd().withIdFilter(id).exec();
} catch (Exception e) {
LOGGER.trace("Error encountered when looking up network for removal (name: {}) - it may not have been removed", id);
return;
}
// using a for loop we essentially treat the network like an optional, only applying the removal if it exists
for (Network network : networks) {
try {
dockerClient.removeNetworkCmd(network.getId()).exec();
registeredNetworks.remove(network.getId());
LOGGER.debug("Removed network: {}", id);
} catch (Exception e) {
LOGGER.trace("Error encountered removing network (name: {}) - it may not have been removed", network.getName());
}
}
} finally {
registeredNetworks.remove(id);
}
}
Aggregations