@Deprecated @Override public void removeContainer(final String containerId, final boolean removeVolumes) throws DockerException, InterruptedException { removeContainer(containerId, RemoveContainerParam.removeVolumes(removeVolumes)); }
@Override public void removeContainer(final String containerId, final RemoveContainerParam... params) throws DockerException, InterruptedException { try { WebTarget resource = resource().path("containers").path(containerId); for (final RemoveContainerParam param : params) { resource = resource.queryParam(param.name(), param.value()); } request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource()), e); case 404: throw new ContainerNotFoundException(containerId, e); default: throw e; } } }
/** * 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); } }
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); } }
@Override public void removeContainer(final String containerId, final RemoveContainerParam... params) throws DockerException, InterruptedException { try { WebTarget resource = resource().path("containers").path(containerId); for (final RemoveContainerParam param : params) { resource = resource.queryParam(param.name(), param.value()); } request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource()), e); case 404: throw new ContainerNotFoundException(containerId, e); default: throw 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); } }
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); } }
/** * Remove the volumes associated to the container. If not specified, defaults to false. * * @return RemoveContainerParam */ public static RemoveContainerParam removeVolumes() { return removeVolumes(true); }
/** * Kill then remove the container. If not specified, defaults to false. * * @param force Whether to force kill before removing. * @return RemoveContainerParam */ public static RemoveContainerParam forceKill(final boolean force) { return create("force", force ? "1" : "0"); } }
/** * Kill then remove the container. If not specified, defaults to false. * * @return RemoveContainerParam */ public static RemoveContainerParam forceKill() { return forceKill(true); }
/** * Remove the volumes associated to the container. If not specified, defaults to false. * * @param remove Whether to remove volumes * @return RemoveContainerParam */ public static RemoveContainerParam removeVolumes(final boolean remove) { return create("v", remove ? "1" : "0"); }
/** * Create a custom parameter. * * @param name custom name * @param value custom value * @return BuildParam */ public static RemoveContainerParam create(final String name, final String value) { return new RemoveContainerParam(name, value); }
@Deprecated @Override public void removeContainer(final String containerId, final boolean removeVolumes) throws DockerException, InterruptedException { removeContainer(containerId, RemoveContainerParam.removeVolumes(removeVolumes)); }
@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); } }
@Override public Void call() throws Exception { dockerClient.removeContainer(containerId, RemoveContainerParam.removeVolumes(removeRunning)); return null; } };
/** * Remove the volumes associated to the container. If not specified, defaults to false. * * @return RemoveContainerParam */ public static RemoveContainerParam removeVolumes() { return removeVolumes(true); }
/** * Create a custom parameter. * * @param name custom name * @param value custom value * @return BuildParam */ public static RemoveContainerParam create(final String name, final String value) { return new RemoveContainerParam(name, value); }
/** * Kill then remove the container. If not specified, defaults to false. * * @return RemoveContainerParam */ public static RemoveContainerParam forceKill() { return forceKill(true); }
/** * Remove the volumes associated to the container. If not specified, defaults to false. * * @param remove Whether to remove volumes * @return RemoveContainerParam */ public static RemoveContainerParam removeVolumes(final boolean remove) { return create("v", remove ? "1" : "0"); }
/** * Kill then remove the container. If not specified, defaults to false. * * @param force Whether to force kill before removing. * @return RemoveContainerParam */ public static RemoveContainerParam forceKill(final boolean force) { return create("force", force ? "1" : "0"); } }