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); } } }
.awaitStatusCode(); docker.removeContainerCmd(container.getId()).exec(); if (exitCode != 0) { throw new PluginException("Build Project Error ExitCode: " + exitCode);
public void removeContainer(String containerId, boolean removeVolumes) { this.readWriteLock.readLock().lock(); try { this.dockerClient.removeContainerCmd(containerId).withRemoveVolumes(removeVolumes).exec(); } finally { this.readWriteLock.readLock().unlock(); } }
public void removeContainer(String containerId, boolean removeVolumes) { this.readWriteLock.readLock().lock(); try { this.dockerClient.removeContainerCmd(containerId).withRemoveVolumes(removeVolumes).exec(); } finally { this.readWriteLock.readLock().unlock(); } }
@Override public void delete(ExecutionContext context) { super.delete(context); if (containerId == null) { throw new ProviderResourcesNotFoundException("Container has not been created yet"); } log.info("Deleting container with id " + containerId, context); connection.getDockerClient().removeContainerCmd(containerId).exec(); log.info("Deleted container with id " + containerId, context); containerId = null; }
/** * 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; } } }
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 killAllSchedulers() { getSchedulerContainers().forEach(container -> dockerClient.removeContainerCmd(container.getId()).withRemoveVolumes(true).withForce(true).exec()); } }
@Override public void terminateVM(String instanceId) throws IaasException { try { this.docker.killContainerCmd(instanceId).exec(); this.docker.removeContainerCmd(instanceId).exec(); } catch(Exception e) { throw new IaasException(e); } }
@Override public void stopAndRemoveContainer(String containerId) { dockerClient.stopContainerCmd(containerId).exec(); dockerClient.removeContainerCmd(containerId).withRemoveVolumes(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 static void dockerRm(String containerId) { try { dockerClient.killContainerCmd(containerId).exec(); } catch (Throwable t) { // pass if the container is not running, no need to kill it } try { dockerClient.removeContainerCmd(containerId).exec(); System.out.printf("cleaned test container %s\n", containerId); } catch (Throwable t) { System.out.printf("Failed to clean test container %s: %s\n", containerId, t.toString()); } }
/** * 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); } }
@Override public void deleteContainer(ContainerName containerName) { try { dockerClient.removeContainerCmd(containerName.asString()).exec(); } catch (NotFoundException e) { throw new ContainerNotFoundException(containerName); } catch (RuntimeException e) { numberOfDockerDaemonFails.add(); throw new DockerException("Failed to delete container '" + containerName.asString() + "'", e); } }
@AfterEach public void stopAndRemoveStartedContainers() { dockerClient.listContainersCmd().exec().stream() .filter(container -> !existingContainers.contains(container)) .forEach(container -> { dockerClient.stopContainerCmd(container.getId()).exec(); dockerClient.removeContainerCmd(container.getId()).exec(); }); }
public void verifyAllClean() { if (remainingContainers == null) updateRemainings(); remainingContainers .forEach(container -> { dockerClient.stopContainerCmd(container.getId()).exec(); dockerClient.removeContainerCmd(container.getId()).exec(); }); assertThat(remainingContainers).isEmpty(); }
private void stopAndRemoveContainer(String containerId) { this.dockerClient.stopContainerCmd(containerId).withTimeout(this.stopContainerTimeout).exec(); this.dockerClient.removeContainerCmd(containerId).withForce(true).exec(); }