@AfterClass public static void tearDown() { RegistryAuthLocator.setInstance(originalAuthLocatorSingleton); client.removeImageCmd(testImageNameWithTag).withForce(true).exec(); }
@Test public void runCommandInsideDockerShouldNotFailIfImageDoesNotExistsLocally() { final DockerClientFactory dockFactory = DockerClientFactory.instance(); try { //remove tiny image, so it will be pulled during next command run dockFactory.client() .removeImageCmd(TestcontainersConfiguration.getInstance().getTinyImage()) .withForce(true).exec(); } catch (NotFoundException ignored) { // Do not fail if it's not pulled yet } dockFactory.runInsideDocker( cmd -> cmd.withCmd("sh", "-c", "echo 'SUCCESS'"), (client, id) -> client.logContainerCmd(id) .withStdOut(true) .exec(new LogToStringContainerCallback()) .toString() ); }
private void putImageInRegistry() throws InterruptedException { // It doesn't matter which image we use for this test, but use one that's likely to have been pulled already final String dummySourceImage = TestcontainersConfiguration.getInstance().getRyukImage(); client.pullImageCmd(dummySourceImage) .exec(new PullImageResultCallback()) .awaitCompletion(1, TimeUnit.MINUTES); final String id = client.inspectImageCmd(dummySourceImage) .exec() .getId(); // push the image to the registry client.tagImageCmd(id, testImageName, "latest").exec(); client.pushImageCmd(testImageNameWithTag) .exec(new PushImageResultCallback()) .awaitCompletion(1, TimeUnit.MINUTES); // remove the image tag from local docker so that it must be pulled before use client.removeImageCmd(testImageNameWithTag).withForce(true).exec(); } }
public void removeImage(String contaierID, Boolean force) { this.readWriteLock.readLock().lock(); try { this.dockerClient.removeImageCmd(contaierID).withForce(force).exec(); } finally { this.readWriteLock.readLock().unlock(); } }
public void removeImage(String contaierID, Boolean force) { this.readWriteLock.readLock().lock(); try { this.dockerClient.removeImageCmd(contaierID).withForce(force).exec(); } finally { this.readWriteLock.readLock().unlock(); } }
public void removeImageById(String imageId) throws NotFoundException, NotModifiedException { dockerClient.removeImageCmd(imageId).withForce(true).exec(); LoggingService.logInfo(MODULE_NAME, String.format("image \"%s\" removed", imageId)); }
private void cleanImages(String id) throws IOException { try(final DockerClient client = getClient()) { client.removeImageCmd(id) .withForce(true) .exec(); } }
private void cleanImage(final Id id, final boolean force) { if (id == null) { throw new IllegalArgumentException("id is null"); } String imageId = null; try { imageId = findImageId(id); } catch (NotFoundException e) { logger.warn("Image " + id + " not found"); } catch (DockerException e) { throw new OrchestrationException(e); } if (imageId != null) { logger.info("Removing image " + imageId); try { docker.removeImageCmd(imageId) .withForce(force) .exec(); } catch (DockerException e) { logger.warn(e.getMessage()); } } }
log.info("Removing image tagged {}", dockerImageName); try { dockerClientForCleaning.removeImageCmd(dockerImageName).withForce(true).exec(); } catch (Throwable e) { log.warn("Unable to delete image " + dockerImageName, e);
/** * Produces a remove image request * * @param client * @param message * @return */ private RemoveImageCmd executeRemoveImageRequest(DockerClient client, Message message) { LOGGER.debug("Executing Docker Remove Image Request"); String imageId = DockerHelper.getProperty(DockerConstants.DOCKER_IMAGE_ID, configuration, message, String.class); ObjectHelper.notNull(imageId, "Image ID must be specified"); RemoveImageCmd removeImagesCmd = client.removeImageCmd(imageId); Boolean force = DockerHelper.getProperty(DockerConstants.DOCKER_FORCE, configuration, message, Boolean.class); if (force != null) { removeImagesCmd.withForce(force); } Boolean noPrune = DockerHelper.getProperty(DockerConstants.DOCKER_NO_PRUNE, configuration, message, Boolean.class); if (noPrune != null) { removeImagesCmd.withNoPrune(noPrune); } return removeImagesCmd; }
.withForce(true) .exec();