public void stopContainer(String containerId) { try { dockerClient.stopContainer(containerId, 5); } catch (ContainerNotFoundException e) { logger.debug("Container {} does not exist - already shut down?.", containerId); } catch (DockerException | InterruptedException e) { logger.warn(nodeId + " Error while stopping the container", e); ga.trackException(e); } }
/** * Stops this container. */ public void stop() throws InterruptedException { // Tell docker to stop or eventually kill the container final String container = containerId.or(containerName); // Interrupt the thread blocking on waitContainer stopAsync().awaitTerminated(); if (System.getenv("CONTAINER_STATS") != null) { try { log.info("container {} stats: {}", containerName, docker.stats(containerName)); } catch (DockerException e) { log.warn("Could not log container stats. Exception was {}", e); } } try { docker.stopContainer(container, secondsToWaitBeforeKill); } catch (DockerException e) { if ((e instanceof ContainerNotFoundException) && !containerId.isPresent()) { // we tried to stop the container by name but no container of the given name existed. // this isn't surprising or exceptional, just means the container wasn't started yet. } else { log.warn("Stopping container {} failed", container, e); } } }
@Override public Void call() throws Exception { dockerClient.stopContainer(containerId, timeout); return null; } };
@SneakyThrows public void stop() { dockerClient.stopContainer(containerInfo.name(), 10); }
public void stopAndRemove(String containerId) { try { dockerClient.stopContainer(containerId, 10); dockerClient.removeContainer(containerId); } catch (DockerException | InterruptedException e) { logger.error("", e); } }
private void stopContainer(String id) throws DockerException, InterruptedException { logger().info("Stopping container #{}", id); client.stopContainer(id, 0); }
/** * Utility method to stop a container with the given image name and id/name. * * @param image * image name * @param idOrName * container id or name */ private void stopContainerQuietly(final String image, final String idOrName) { final long startTime = System.currentTimeMillis(); try { LOGGER.info("Killing docker container {} with id {}", image, idOrName); final int secondsToWaitBeforeKilling = 10; client.stopContainer(containerId, secondsToWaitBeforeKilling); } catch (DockerException | InterruptedException e) { // log error and ignore exception LOGGER.warn("Unable to kill docker container {} with id", image, idOrName, e); } finally { final long elapsedMillis = System.currentTimeMillis() - startTime; LOGGER.info("Docker container {} with id {} killed in {}ms", image, idOrName, elapsedMillis); } }
/** * Stops this container. */ public void stop() throws InterruptedException { // Tell docker to stop or eventually kill the container final String container = containerId.or(containerName); // Interrupt the thread blocking on waitContainer stopAsync().awaitTerminated(); try { docker.stopContainer(container, SECONDS_TO_WAIT_BEFORE_KILL); } catch (DockerException e) { if ((e instanceof ContainerNotFoundException) && !containerId.isPresent()) { // we tried to stop the container by name but no container of the given name existed. // this isn't surprising or exceptional, just means the container wasn't started yet. } else { log.warn("Stopping container {} failed", container, e); } } }
public synchronized void stopContainer(String containerId) throws DockerException, InterruptedException { int stopTimeoutSec = getConfig().getDockerStopTimeoutSec(); if (stopTimeoutSec == 0) { log.trace("Killing container {}", containerId); dockerClient.killContainer(containerId, SIGKILL); } else { log.trace("Stopping container {} (timeout {} seconds)", containerId, stopTimeoutSec); dockerClient.stopContainer(containerId, stopTimeoutSec); } }
@Override public void close() { try { client.stopContainer(containerInfo.id(), 10); client.removeContainer(containerInfo.id()); } catch (DockerException | InterruptedException e) { logger.error("Error stopping 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; }
/** * This method attempts to gracefully stop a container and kill it after timeout. * * @param timeout a duration after which the stop will kill the container * @throws NodeException this exception will be thrown if a container cannot be stopped. */ public void stop(String containerName, Duration timeout) { log.info("Stopping the Corfu server. Docker container: {}", containerName); try { ContainerInfo container = docker.inspectContainer(containerName); if (!container.state().running() && !container.state().paused()) { log.warn("The container `{}` is already stopped", container.name()); return; } docker.stopContainer(containerName, (int) timeout.getSeconds()); } catch (DockerException | InterruptedException e) { throw new NodeException("Can't stop Corfu server: " + containerName, e); } }
@Override public void stop(RuntimeId runtimeId) throws RuntimeOperationException { DockerRuntime runtime = (DockerRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId()); try { LOG.info("Stopping container: " + runtimeId.getId()); docker.getDockerClient(runtime.getProviderId()).stopContainer(runtime.getId(), 1); refresh(runtimeId); } catch (DockerException | InterruptedException ex) { LOG.error("Error Stopping container: " + runtimeId.getId(), ex); throw new RuntimeOperationException("Error Stopping container: " + runtimeId.getId(), ex); } }
@Override public void stop(RuntimeId runtimeId) throws RuntimeOperationException { DockerRuntime runtime = (DockerRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId()); try { LOG.info("Stopping container: " + runtimeId.getId()); docker.getDockerClient(runtime.getProviderId()).stopContainer(runtime.getId(), 1); refresh(runtimeId); } catch (DockerException | InterruptedException ex) { LOG.error("Error Stopping container: " + runtimeId.getId(), ex); throw new RuntimeOperationException("Error Stopping container: " + runtimeId.getId(), ex); } }
/** * Stop and remove container.<br/> * This is {@link ExternalResource#before()} made available as public - it may be helpful in scenarios * when you want to use {@link DockerRule} and operate it manually. */ @Override public final void after() { log.debug("after {}", containerShortId); try { dockerLogs.close(); ContainerState state = dockerClient.inspectContainer(container.id()).state(); log.debug("{} state {}", containerShortId, state); if (state.running()) { if (builder.stopOptions().contains(StopOption.KILL)) { dockerClient.killContainer(container.id()); log.info("{} killed", containerShortId); } else { dockerClient.stopContainer(container.id(), STOP_TIMEOUT); log.info("{} stopped", containerShortId); } } if (builder.stopOptions().contains(StopOption.REMOVE)) { dockerClient.removeContainer(container.id(), DockerClient.RemoveContainerParam.removeVolumes()); log.info("{} deleted", containerShortId); container = null; } } catch (DockerException | InterruptedException e) { throw new IllegalStateException(e); } }
public void close(DockerClient dockerClient) throws DockerException, InterruptedException { dockerClient.stopContainer(container.id(), 10); dockerClient.removeContainer(container.id()); }