/** * Check whether the image is available locally and pull it otherwise */ public void checkAndPullImage(DockerClient client, String image) { List<Image> images = client.listImagesCmd().withImageNameFilter(image).exec(); if (images.isEmpty()) { client.pullImageCmd(image).exec(new PullImageResultCallback()).awaitSuccess(); } }
dockerClient.pullImageCmd(image).withRegistry(registry.getUrl()) : dockerClient.pullImageCmd(image).withAuthConfig( new AuthConfig() .withRegistryAddress(registry.getUrl()) ); if (tag != null) req.withTag(tag); PullImageResultCallback res = new PullImageResultCallback(); res = req.exec(res); res.awaitSuccess();
/** * Pull docker image using the docker java client. * * @param imageTag * @param username * @param password * @param host */ public static void pullImage(String imageTag, String username, String password, String host) throws IOException { final AuthConfig authConfig = new AuthConfig(); authConfig.withUsername(username); authConfig.withPassword(password); DockerClient dockerClient = null; try { dockerClient = getDockerClient(host); dockerClient.pullImageCmd(imageTag).withAuthConfig(authConfig).exec(new PullImageResultCallback()).awaitSuccess(); } finally { closeQuietly(dockerClient); } }
/** * Produces a pull image request * * @param client * @param message * @return */ private PullImageCmd executePullImageRequest(DockerClient client, Message message) { LOGGER.debug("Executing Docker Pull Image Request"); String repository = DockerHelper.getProperty(DockerConstants.DOCKER_REPOSITORY, configuration, message, String.class); ObjectHelper.notNull(repository, "Repository must be specified"); PullImageCmd pullImageCmd = client.pullImageCmd(repository); String registry = DockerHelper.getProperty(DockerConstants.DOCKER_REGISTRY, configuration, message, String.class); if (registry != null) { pullImageCmd.withRegistry(registry); } String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class); if (tag != null) { pullImageCmd.withTag(tag); } AuthConfig authConfig = client.authConfig(); if (authConfig != null) { pullImageCmd.withAuthConfig(authConfig); } return pullImageCmd; }
dockerClient.pullImageCmd(imageName.getUnversionedPart()).withTag(imageName.getVersionPart()).exec(callback); callback.awaitCompletion(); AVAILABLE_IMAGE_NAME_CACHE.add(imageName);
private static void setAuthFromFile(final PullImageCmd pullImageCmd, final DefaultDockerClientConfig dockerClientConfig, final String imageName) { final AuthConfig authConfig = dockerClientConfig.effectiveAuthConfig(imageName); if (authConfig != null) { pullImageCmd.withAuthConfig(authConfig); } }
pullImageCmd.withAuthConfig(authConfig); pullImageCmd.exec(pullImageResultCallback);
@Restricted(NoExternalUse.class) public static void setRegistryAuthentication(PullImageCmd cmd, DockerRegistryEndpoint registry, ItemGroup context) { if (registry != null && registry.getCredentialsId() != null) { AuthConfig auth = getAuthConfig(registry, context); cmd.withAuthConfig(auth); } }
private void tagImage(String sourceImage, String targetImage, String targetTag) throws InterruptedException { DockerClient client = DockerClientFactory.instance().client(); client.pullImageCmd(sourceImage).exec(new PullImageResultCallback()).awaitCompletion(); client.tagImageCmd(sourceImage, targetImage, targetTag).exec(); } }
public void pullImage(String imageName) { this.readWriteLock.readLock().lock(); try { final Image image = Image.valueOf(imageName); PullImageCmd pullImageCmd = this.dockerClient.pullImageCmd(image.getName()); String tag = image.getTag(); if (tag != null && !"".equals(tag)) { pullImageCmd.withTag(tag); } else { pullImageCmd.withTag("latest"); } pullImageCmd.exec(new PullImageResultCallback()).awaitSuccess(); } finally { this.readWriteLock.readLock().unlock(); } }
public void pull(String image) { log.info("Pull Image " + image + " Start"); try { docker .pullImageCmd(image) .exec(new PullImageProcess()) .awaitCompletion(); } catch (InterruptedException e) { log.error("Pull Image Error", e); throw new PluginException("Pull Image Error"); } log.info("Pull Image " + image + " Success"); }
public void pullImage(String imageName) { this.readWriteLock.readLock().lock(); try { final Image image = Image.valueOf(imageName); PullImageCmd pullImageCmd = this.dockerClient.pullImageCmd(image.getName()); String tag = image.getTag(); if (tag != null && !"".equals(tag)) { pullImageCmd.withTag(tag); } else { pullImageCmd.withTag("latest"); } pullImageCmd.exec(new PullImageResultCallback()).awaitSuccess(); } finally { this.readWriteLock.readLock().unlock(); } }
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 void pullImageIfNeeded() { final List<Image> images = client.listImagesCmd().withImageNameFilter(image).exec(); if (images.isEmpty()) { log.info("Pulling " + image); final String[] parts = image.split(":"); client.pullImageCmd(parts[0]).withTag(parts[1]).exec(new PullImageResultCallback()).awaitSuccess(); log.info(image + " pulled"); } }
public void pullImage(String image){ dockerClient.pullImageCmd(image).exec(); }
/** * Pulls a Docker image with given name and version. Throws exception when it times out after given timeout. * * @param imageName image to pull * @param imageVersion image version to pull * @param timeoutSecs pulling timeout in seconds */ public static void pullImage(String imageName, String imageVersion, long timeoutSecs) { try { final CompletableFuture<Void> result = new CompletableFuture<>(); DockerClientFactory.build().pullImageCmd(imageName).withTag(imageVersion).exec(new PullImageResultCallback()).awaitCompletion(); } catch (InterruptedException | RuntimeException e) { throw new MinimesosException("Error pulling image or image not found in registry: " + imageName + ":" + imageVersion, e); } }
public void pullImageIfNecessary(String imageId, boolean force) { if (imageId.isEmpty()) { return; } if (force || !existsImage(imageId)) { log.debug("Pulling Docker image {} ... please be patient until the process finishes", imageId); try { getClient().pullImageCmd(imageId).exec(new PullImageResultCallback()).awaitCompletion(); } catch (Exception e) { log.warn("Exception pulling image {}", imageId, e); } log.debug("Image {} downloaded", imageId); } else { log.debug("Image {} already exists", imageId); } }
public void pullImageIfNecessary(String imageId, boolean force) { if (imageId.isEmpty()) { return; } if (force || !existsImage(imageId)) { log.debug("Pulling Docker image {} ... please be patient until the process finishes", imageId); try { getClient().pullImageCmd(imageId).exec(new PullImageResultCallback()).awaitCompletion(); } catch (Exception e) { log.warn("Exception pulling image {}", imageId, e); } log.debug("Image {} downloaded", imageId); } else { log.debug("Image {} already exists", imageId); } }