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(); } }
private ContainerConfig getImageConfig() { return this.actual.getConfig(); } }
while (true) { InspectImageResponse iir = cl.inspectImageCmd(img.getId()).exec(); String[] cmd = iir.getContainerConfig().getCmd(); String cmdLine; if (cmd.length == 3 && cmd[0].equals("/bin/sh") && cmd[1].equals("-c")) {
/** * Get parent digest of an image. * * @param digest * @param host * @return */ public static String getParentId(String digest, String host) throws IOException { DockerClient dockerClient = null; try { dockerClient = getDockerClient(host); return dockerClient.inspectImageCmd(digest).exec().getParent(); } finally { closeQuietly(dockerClient); } }
@Restricted(NoExternalUse.class) public DockerTransientNode provisionNode(DockerAPI api, TaskListener listener) throws IOException, Descriptor.FormException, InterruptedException { try { final InspectImageResponse image = pullImage(api, listener); if (StringUtils.isBlank(remoteFs)) { remoteFs = image.getContainerConfig().getWorkingDir(); } if (StringUtils.isBlank(remoteFs)) { remoteFs = "/"; } try(final DockerClient client = api.getClient()) { return doProvisionNode(api, client, listener); } } catch (IOException | Descriptor.FormException | InterruptedException | RuntimeException ex) { final DockerCloud ourCloud = DockerCloud.findCloudForTemplate(this); final long milliseconds = ourCloud == null ? 0L : ourCloud.getEffectiveErrorDurationInMilliseconds(); if (milliseconds > 0L) { // if anything went wrong, disable ourselves for a while final String reason = "Template provisioning failed."; final DockerDisabled reasonForDisablement = getDisabled(); reasonForDisablement.disableBySystem(reason, milliseconds, ex); setDisabled(reasonForDisablement); } throw ex; } }
/** * Get image Id from imageTag using DockerBuildInfoHelper client. * * @param imageTag * @param host * @return */ public static String getImageIdFromTag(String imageTag, String host) throws IOException { DockerClient dockerClient = null; try { dockerClient = getDockerClient(host); return dockerClient.inspectImageCmd(imageTag).exec().getId(); } finally { closeQuietly(dockerClient); } }
@BeforeEach public void ensureContainerIsNotPresent() { try { String imageToRemove = dockerClient.inspectImageCmd(WANTED_IMAGE).exec().getId(); dockerClient.removeImageCmd(imageToRemove).exec(); } catch (NotFoundException e) { // not found, no problems } }