@Override public Object call() throws Exception { try { dockerClient.killContainer(containerId); } catch (DockerRequestException e) { if (e.getResponseBody().contains("is not running")) { // Container already isn't running. So we continue. } else { throw e; } } try { dockerClient.removeContainer(containerId); return true; } catch (ContainerNotFoundException e) { // We're done here return true; } catch (DockerException e) { if ((e instanceof DockerRequestException) && ((DockerRequestException) e).getResponseBody().contains( "Driver btrfs failed to remove root filesystem")) { // Workaround btrfs issue where removing containers throws an exception, // but succeeds anyway. return true; } else { return null; } } } });
@Override public Void call() throws Exception { dockerClient.removeContainer(containerId, RemoveContainerParam.removeVolumes(removeRunning)); return null; } };
public void stopAndRemove(String containerId) { try { dockerClient.stopContainer(containerId, 10); dockerClient.removeContainer(containerId); } catch (DockerException | InterruptedException e) { logger.error("", e); } }
private void killDockerContainer(DockerClient docker, String containerId) { LOGGER.info("Killing docker container: "+containerId); try { docker.killContainer(containerId); docker.removeContainer(containerId); } catch (DockerException|InterruptedException e) { LOGGER.error("Error while killing docker container "+containerId, e); } }
private void removeContainer(String id) throws DockerException, InterruptedException { logger().info("Removing container #{}", id); client.removeContainer(id); }
public synchronized void removeContainer(String containerId) throws DockerException, InterruptedException { log.trace("Removing container {}", containerId); int stopTimeoutSec = getConfig().getDockerStopTimeoutSec(); if (stopTimeoutSec == 0) { dockerClient.removeContainer(containerId, forceKill()); } else { dockerClient.removeContainer(containerId); } }
/** * Immediately kill and remove a docker container * * @throws NodeException this exception will be thrown if the container can not be killed. */ public void destroy(String containerName) { log.info("Destroying docker container: {}", containerName); try { kill(containerName); } catch (NodeException ex) { log.warn("Can't kill container: {}", containerName); } try { docker.removeContainer(containerName); } catch (DockerException | InterruptedException ex) { throw new NodeException("Can't destroy Corfu server. Already deleted. Container: " + containerName, ex); } }
/** * Stops PostgreSql. * * @throws Exception If fails to stop PostgreSql. */ public void stopPostgreSql() throws Exception { // Close all the connections for (Connection connection : this.connections) { try { connection.close(); } catch (SQLException ex) { // ignore failure } } // Stop PostgresSQL System.out.println("Stopping PostgreSQL"); this.docker.killContainer(this.postgresContainerId); this.docker.removeContainer(this.postgresContainerId); this.docker.close(); }
@Override public void close() { try { client.stopContainer(containerInfo.id(), 10); client.removeContainer(containerInfo.id()); } catch (DockerException | InterruptedException e) { logger.error("Error stopping container", e); } } }
private void killAndRemoveContainer(DockerClient docker, Container container) { try { if (container.status().startsWith("Up")) { LOG.debug("Killing Couchbase Docker container"); docker.killContainer(container.id()); } LOG.debug("Removing Couchbase Docker container"); docker.removeContainer(container.id()); } catch (DockerException | InterruptedException e) { throw new EnvironmentBuilderException("Unable to kill and remove a container", e); } }
private void removeContainerQuietly(final String idOrName) { final long startTime = System.currentTimeMillis(); try { LOGGER.info("Removing docker container {} with id {}", containerConfig.image(), idOrName); client.removeContainer(idOrName, RemoveContainerParam.removeVolumes(true)); } catch (DockerException | InterruptedException e) { // log error and ignore exception LOGGER.warn( "Unable to remove docker container {} with id {}", containerConfig.image(), idOrName, e); } finally { final long elapsedMillis = System.currentTimeMillis() - startTime; LOGGER.info( "Container {} with id {} removed in {}ms", containerConfig.image(), idOrName, elapsedMillis); } }
private void killAndRemoveContainer(Container container) { try { if (container.status().startsWith("Up")) { LOG.debug("Killing Docker container '{}'", containerName); dockerClient.killContainer(container.id()); } LOG.debug("Removing Docker container '{}'", containerName); dockerClient.removeContainer(container.id()); } catch (DockerException | InterruptedException e) { throw new EnvironmentBuilderException("Unable to kill and remove a container", e); } }
@Override public void close() { try { client.stopContainer(containerInfo.id(), 10); client.removeContainer(containerInfo.id()); } catch (DockerException | InterruptedException e) { logger.error("Error stopping container", e); } client.close(); isClosed = true; }
/** * In case of timeout, we kill the container. * @param remove if true, it will remove both the container and the volumes */ public void killDockerContainer(DockerClient docker, boolean remove) { if (this.containerId == null) { LOGGER.error("Error while trying to kill docker container: the container id is not available. Maybe the container is not started yet."); } else { LOGGER.info("Killing the docker container with id "+containerId+". Forced killing date: "+this.limitDateBeforeKilling); try { docker.killContainer(containerId); if (remove) { docker.removeContainer(containerId); this.removeVolumes(docker); } this.poolManager.removeSubmittedRunnablePipelineContainer(this); serialize("INTERRUPTED"); } catch (DockerException|InterruptedException e) { LOGGER.error("Error while killing docker container "+containerId, e); } } }
public void killAndRemoveContainer() { try { ContainerState state = dockerClient.inspectContainer(containerId).state(); if (Boolean.TRUE.equals(state.running())) { dockerClient.killContainer(containerId); } if (dockerHost.isRemove()) { dockerClient.removeContainer(containerId, removeVolumes(dockerHost.isRemoveVolume())); } } catch (InterruptedException | DockerException e) { logger.error("Error while tearing down docker container", e); throw new RuntimeException("Error while tearing down docker container", e); } }
@Override public void destroy(final RuntimeId runtimeId) { try { LOG.info("Killing Container: " + runtimeId.getId()); docker.getDockerClient(runtimeId.getProviderId()).killContainer(runtimeId.getId()); LOG.info("Removing Container: " + runtimeId.getId()); docker.getDockerClient(runtimeId.getProviderId()).removeContainer(runtimeId.getId()); runtimeRegistry.deregisterRuntime(runtimeId); } catch (DockerException | InterruptedException ex) { LOG.debug(ex.getMessage(), ex); try { // Trying to remove the container if it cannot be killed LOG.info("Attempting to Remove Container without Killing: " + runtimeId.getId()); docker.getDockerClient(runtimeId.getProviderId()).removeContainer(runtimeId.getId()); runtimeRegistry.deregisterRuntime(runtimeId); } catch (DockerException | InterruptedException ex2) { LOG.error(ex.getMessage(), ex2); throw new ProvisioningException("Error destroying Docker Runtime: " + ex.getMessage(), ex2); } } } }
@Override protected void after() { super.after(); try { dockerClient.killContainer(container.id()); dockerClient.removeContainer(container.id(), removeVolumes()); dockerClient.close(); } catch (DockerException | InterruptedException e) { throw new RuntimeException("Unable to stop/remove docker container " + container.id(), e); } }
public void close(DockerClient dockerClient) throws DockerException, InterruptedException { dockerClient.stopContainer(container.id(), 10); dockerClient.removeContainer(container.id()); }
public static void before() throws Throwable { if (existContainer()) { logger.info("Container exists, removing"); if (elasticsearchRule.getDockerClient().inspectContainer(CONTAINER_NAME).state().running()) { elasticsearchRule.getDockerClient().killContainer(CONTAINER_NAME); } elasticsearchRule.getDockerClient().removeContainer(CONTAINER_NAME); } else { logger.info("Container does not exist"); } logger.info("Creating container"); elasticsearchRule.before(); }
public static void before() throws Throwable { if (existContainer()) { logger.info("Container exists, removing"); if (elasticsearchRule.getDockerClient().inspectContainer(CONTAINER_NAME).state().running()) { elasticsearchRule.getDockerClient().killContainer(CONTAINER_NAME); } elasticsearchRule.getDockerClient().removeContainer(CONTAINER_NAME); } else { logger.info("Container does not exist"); } logger.info("Creating container"); elasticsearchRule.before(); }