LOGGER.trace("Removing container: {}", containerId); try { dockerClient.removeContainerCmd(containerId).withRemoveVolumes(true).withForce(true).exec(); LOGGER.debug("Removed container and associated volume(s): {}", imageName); } catch (InternalServerErrorException e) {
private <T> T runInsideDocker(DockerClient client, Consumer<CreateContainerCmd> createContainerCmdConsumer, BiFunction<DockerClient, String, T> block) { checkAndPullImage(client, TINY_IMAGE); CreateContainerCmd createContainerCmd = client.createContainerCmd(TINY_IMAGE) .withLabels(DEFAULT_LABELS); createContainerCmdConsumer.accept(createContainerCmd); String id = createContainerCmd.exec().getId(); try { client.startContainerCmd(id).exec(); return block.apply(client, id); } finally { try { client.removeContainerCmd(id).withRemoveVolumes(true).withForce(true).exec(); } catch (NotFoundException | InternalServerErrorException ignored) { log.debug("", ignored); } } }
/** * removes a {@link Container} * * @param id - id of {@link Container} * @param withRemoveVolumes - true or false, Remove the volumes associated to the container */ public void removeContainer(String id, Boolean withRemoveVolumes) throws NotFoundException, NotModifiedException { dockerClient.removeContainerCmd(id).withForce(true).withRemoveVolumes(withRemoveVolumes).exec(); }
private void removeContainer(Container existingContainer) { logger.info("Removing container " + existingContainer.getId()); try { docker.removeContainerCmd(existingContainer.getId()).withForce(true).withRemoveVolumes(true).exec(); } catch (InternalServerErrorException e) { if (permissionErrorTolerant && isPermissionError(e)) { logger.warn(String.format("ignoring %s when removing container as we are configured to be permission error tolerant", e)); } else { throw e; } } }
public void killAllSchedulers() { getSchedulerContainers().forEach(container -> dockerClient.removeContainerCmd(container.getId()).withRemoveVolumes(true).withForce(true).exec()); } }
private boolean isRunning() { final List<Container> all = client.listContainersCmd().withShowAll(true).withLabelFilter(label).exec(); final List<Container> running = client.listContainersCmd().withStatusFilter("running").withLabelFilter(label).exec(); all.stream() .filter(c -> running.isEmpty() || !running.get(0).getId().equals(c.getId())) .forEach(c -> client.removeContainerCmd(c.getId()).withForce(true).exec()); return !running.isEmpty(); }
public void killAllExecutors() { getExecutorContainers().forEach(container -> dockerClient.removeContainerCmd(container.getId()).withRemoveVolumes(true).withForce(true).exec()); }
public Void call() throws Exception { DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, null); client.removeContainerCmd(id).withForce(force).withRemoveVolumes(removeVolumes).exec(); return null; }
private void terminateContainer(DockerCloud dc, DockerClient client, Container container) { boolean gracefulFailed = false; try { terminateContainerGracefully(dc, container); } catch (TerminationException e) { gracefulFailed = true; } catch (ContainerIsTaintedException e) { LOGGER.warn("Container {} has been tampered with; skipping cleanup", container.getId(), e); return; } if (gracefulFailed) { try { Instant start = clock.instant(); client.removeContainerCmd(container.getId()).withForce(true).exec(); Instant stop = clock.instant(); executionStatistics.addContainerRemovalForce(Duration.between(start, stop).toMillis()); } catch (RuntimeException e) { LOGGER.warn("Forced termination of container {} failed with RuntimeException", container.getId(), e); executionStatistics.addContainerRemovalFailed(); } } }
/** * Removes all containers in the util object */ public void remove() { if (containers != null) { for (Container container : containers) { DockerClientFactory.build().removeContainerCmd(container.getId()).withForce(true).withRemoveVolumes(true).exec(); } } }
/** * Removes a container with force */ @Override public void remove() { try { if (DockerContainersUtil.getContainer(containerId) != null) { DockerClientFactory.build().removeContainerCmd(containerId).withForce(true).withRemoveVolumes(true).exec(); } } catch (Exception e) { LOGGER.error("Could not remove container " + dockerCommand().getName(), e); } }
/** * Produces a remove container request * * @param client * @param message * @return */ private RemoveContainerCmd executeRemoveContainerRequest(DockerClient client, Message message) { LOGGER.debug("Executing Docker Remove Container Request"); String containerId = DockerHelper.getProperty(DockerConstants.DOCKER_CONTAINER_ID, configuration, message, String.class); ObjectHelper.notNull(containerId, "Container ID must be specified"); RemoveContainerCmd removeContainerCmd = client.removeContainerCmd(containerId); Boolean force = DockerHelper.getProperty(DockerConstants.DOCKER_FORCE, configuration, message, Boolean.class); if (force != null) { removeContainerCmd.withForce(force); } Boolean removeVolumes = DockerHelper.getProperty(DockerConstants.DOCKER_REMOVE_VOLUMES, configuration, message, Boolean.class); if (removeVolumes != null) { removeContainerCmd.withRemoveVolumes(removeVolumes); } return removeContainerCmd; }
LOGGER.trace("Removing container: {}", containerId); try { dockerClient.removeContainerCmd(containerId).withRemoveVolumes(true).withForce(true).exec(); LOGGER.debug("Removed container and associated volume(s): {}", imageName); } catch (InternalServerErrorException e) {
} finally { try { client.removeContainerCmd(id).withRemoveVolumes(true).withForce(true).exec(); } catch (NotFoundException | InternalServerErrorException ignored) { log.debug("", ignored);
private ServiceInstance destroyInstance(ServiceInstance i, DockerClient client) { if(i.getContainerId() != null) { RemoveContainerCmd cmd = client.removeContainerCmd(i.getContainerId()).withForce(true); try { cmd.exec(); return i.withStatus(Status.TERMINATED); } catch (NotFoundException e) { logger.warning("No container with id " + i.getContainerId() + " found"); return i.withStatus(Status.TERMINATION_FAILED) .withStatusDetails(e.getMessage()); } } else { return i.withStatus(Status.TERMINATION_FAILED) .withStatusDetails("No container id found."); } }
@Override public void close() { try { try { client.stopContainerCmd(containerInfo.getId()).withTimeout(30).exec(); } catch (Exception ex) { // no-op } client.removeContainerCmd(containerInfo.getId()) .withForce(true) .withRemoveVolumes(true) .exec(); client.close(); } catch (Exception e) { // no-op } isClosed = true; }
private void stopAndRemoveContainer(String containerId) { this.dockerClient.stopContainerCmd(containerId).withTimeout(this.stopContainerTimeout).exec(); this.dockerClient.removeContainerCmd(containerId).withForce(true).exec(); }
client.removeContainerCmd(containerId).withForce(true).exec(); } catch (NotFoundException ex) { LOGGER.info("Unable to remove container '" + containerId + "' as it had already gone.");