use of io.fabric8.maven.docker.access.DockerAccessException in project docker-maven-plugin by fabric8io.
the class RegistryService method pullImageWithPolicy.
/**
* Check an image, and, if <code>autoPull</code> is set to true, fetch it. Otherwise if the image
* is not existent, throw an error
* @param registryConfig registry configuration
*
* @throws DockerAccessException
* @throws MojoExecutionException
*/
public void pullImageWithPolicy(String image, ImagePullManager pullManager, RegistryConfig registryConfig, boolean hasImage) throws DockerAccessException, MojoExecutionException {
// Already pulled, so we don't need to take care
if (pullManager.hasAlreadyPulled(image)) {
return;
}
// Check if a pull is required
if (!imageRequiresPull(hasImage, pullManager.getImagePullPolicy(), image)) {
return;
}
ImageName imageName = new ImageName(image);
long time = System.currentTimeMillis();
String actualRegistry = EnvUtil.fistRegistryOf(imageName.getRegistry(), registryConfig.getRegistry());
docker.pullImage(imageName.getFullName(), createAuthConfig(false, null, actualRegistry, registryConfig), actualRegistry);
log.info("Pulled %s in %s", imageName.getFullName(), EnvUtil.formatDurationTill(time));
pullManager.pulled(image);
if (actualRegistry != null && !imageName.hasRegistry()) {
// If coming from a registry which was not contained in the original name, add a tag from the
// full name with the registry to the short name with no-registry.
docker.tag(imageName.getFullName(actualRegistry), image, false);
}
}
use of io.fabric8.maven.docker.access.DockerAccessException in project docker-maven-plugin by fabric8io.
the class RunService method execInContainer.
/**
* Create and start a Exec container with the given image configuration.
* @param containerId container id to run exec command against
* @param command command to execute
* @param imageConfiguration configuration of the container's image
* @return the exec container id
*
* @throws DockerAccessException if access to the docker backend fails
*/
public String execInContainer(String containerId, String command, ImageConfiguration imageConfiguration) throws DockerAccessException, ExecException {
Arguments arguments = new Arguments();
arguments.setExec(Arrays.asList(EnvUtil.splitOnSpaceWithEscape(command)));
String execContainerId = docker.createExecContainer(containerId, arguments);
docker.startExecContainer(execContainerId, logConfig.createSpec(containerId, imageConfiguration));
ExecDetails execContainer = docker.getExecContainer(execContainerId);
Integer exitCode = execContainer.getExitCode();
if (exitCode != null && exitCode != 0) {
ContainerDetails container = docker.getContainer(containerId);
throw new ExecException(execContainer, container);
}
return execContainerId;
}
use of io.fabric8.maven.docker.access.DockerAccessException in project docker-maven-plugin by fabric8io.
the class DockerAccessIT method testCreateContainer.
private void testCreateContainer() throws DockerAccessException {
PortMapping portMapping = new PortMapping(Arrays.asList(new String[] { PORT + ":" + PORT }), new Properties());
ContainerHostConfig hostConfig = new ContainerHostConfig().portBindings(portMapping);
ContainerCreateConfig createConfig = new ContainerCreateConfig(IMAGE).command(new Arguments("ping google.com")).hostConfig(hostConfig);
containerId = dockerClient.createContainer(createConfig, CONTAINER_NAME);
assertNotNull(containerId);
String name = dockerClient.getContainer(containerId).getName();
assertEquals(CONTAINER_NAME, name);
}
use of io.fabric8.maven.docker.access.DockerAccessException in project docker-maven-plugin by fabric8io.
the class DockerAccessWinIT method testCreateContainer.
private void testCreateContainer() throws DockerAccessException {
PortMapping portMapping = new PortMapping(Arrays.asList(new String[] { PORT + ":" + PORT }), new Properties());
ContainerHostConfig hostConfig = new ContainerHostConfig().portBindings(portMapping);
ContainerCreateConfig createConfig = new ContainerCreateConfig(IMAGE).command(new Arguments("ping google.com")).hostConfig(hostConfig);
containerId = dockerClient.createContainer(createConfig, CONTAINER_NAME);
assertNotNull(containerId);
String name = dockerClient.getContainer(containerId).getName();
assertEquals(CONTAINER_NAME, name);
}
use of io.fabric8.maven.docker.access.DockerAccessException in project docker-maven-plugin by fabric8io.
the class DockerAccessWinIT method testExecContainer.
private void testExecContainer() throws DockerAccessException {
Arguments arguments = new Arguments();
arguments.setExec(Lists.newArrayList("echo", "test", "echo"));
String execContainerId = dockerClient.createExecContainer(this.containerId, arguments);
// assertThat(dockerClient.startExecContainer(execContainerId), is("test echo"));
}
Aggregations