private void registerContainersForShutdown() { ResourceReaper.instance().registerFilterForCleanup(Arrays.asList( new SimpleEntry<>("label", "com.docker.compose.project=" + project) )); }
@Override public void close() { if (initialized.getAndSet(false)) { ResourceReaper.instance().removeNetworkById(id); } } }
/** * Stops the container. */ @Override public void stop() { if (containerId == null) { return; } try { String imageName; try { imageName = image.get(); } catch (Exception e) { imageName = "<unknown>"; } ResourceReaper.instance().stopAndRemoveContainer(containerId, imageName); } finally { containerId = null; containerInfo = null; } }
@Override public void stop() { synchronized (MUTEX) { try { // shut down the ambassador container ambassadorContainer.stop(); // Kill the services using docker-compose try { runWithCompose("down -v"); // If we reach here then docker-compose down has cleared networks and containers; // we can unregister from ResourceReaper spawnedContainerIds.forEach(ResourceReaper.instance()::unregisterContainer); spawnedNetworkIds.forEach(ResourceReaper.instance()::unregisterNetwork); } catch (Exception e) { // docker-compose down failed; use ResourceReaper to ensure cleanup // kill the spawned service containers spawnedContainerIds.forEach(ResourceReaper.instance()::stopAndRemoveContainer); // remove the networks after removing the containers spawnedNetworkIds.forEach(ResourceReaper.instance()::removeNetworkById); } spawnedContainerIds.clear(); spawnedNetworkIds.clear(); } finally { project = randomProjectId(); } } }