use of io.fabric8.maven.docker.model.ContainerDetails 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.model.ContainerDetails in project docker-maven-plugin by fabric8io.
the class HealthCheckChecker method check.
@Override
public boolean check() {
try {
final ContainerDetails container = docker.getContainer(containerId);
if (container == null) {
log.debug("HealthWaitChecker: Container %s not found");
return false;
}
if (container.getHealthcheck() == null) {
throw new IllegalArgumentException("Can not wait for healthstate of " + imageConfigDesc + ". No HEALTHCHECK configured.");
}
if (first) {
log.info("%s: Waiting to become healthy", imageConfigDesc);
log.debug("HealthWaitChecker: Waiting for healthcheck: '%s'", container.getHealthcheck());
first = false;
} else if (log.isDebugEnabled()) {
log.debug("HealthWaitChecker: Waiting on healthcheck '%s'", container.getHealthcheck());
}
return container.isHealthy();
} catch (DockerAccessException e) {
log.warn("Error while checking health: %s", e.getMessage());
return false;
}
}
Aggregations