use of com.spotify.docker.client.DockerClient in project elastest-torm by elastest.
the class DockerService method getRunningContainersByImageName.
public List<Container> getRunningContainersByImageName(String imageName) throws Exception {
imageName += ":";
DockerClient dockerClient = getDockerClient();
List<Container> allContainers = dockerClient.listContainers(ListContainersParam.allContainers());
List<Container> imageContainers = new ArrayList<>();
for (Container currentContainer : allContainers) {
if (currentContainer.image().startsWith(imageName)) {
imageContainers.add(currentContainer);
}
}
return imageContainers;
}
use of com.spotify.docker.client.DockerClient in project elastest-torm by elastest.
the class DockerService method stopAndRemoveContainerWithKillTimeout.
public void stopAndRemoveContainerWithKillTimeout(String containerId, int killAfterSeconds) throws Exception {
DockerClient dockerClient = getDockerClient();
dockerClient.stopContainer(containerId, killAfterSeconds);
this.removeDockerContainer(containerId);
}
use of com.spotify.docker.client.DockerClient in project elastest-torm by elastest.
the class DockerService method getContainerIpByNetwork.
public String getContainerIpByNetwork(String containerId, String network) throws Exception {
DockerClient client = getDockerClient();
ContainerInfo info = client.inspectContainer(containerId);
String ip = info.networkSettings().networks().get(network).ipAddress();
return ip.split("/")[0];
}
use of com.spotify.docker.client.DockerClient in project elastest-torm by elastest.
the class DockerService method getContainerLogsByGivenLogContainerCmd.
public String getContainerLogsByGivenLogContainerCmd(String containerId, List<LogsParam> params) throws Exception {
params.add(LogsParam.stdout(true));
params.add(LogsParam.stderr(true));
params.add(LogsParam.timestamps(true));
DockerClient dockerClient = getDockerClient();
LogStream logStream = dockerClient.logs(containerId, params.toArray(new LogsParam[params.size()]));
return logStream.readFully();
}
use of com.spotify.docker.client.DockerClient in project elastest-torm by elastest.
the class DockerService method removeDockerContainer.
public void removeDockerContainer(String containerId, boolean removeVolumes) throws Exception {
DockerClient dockerClient = getDockerClient();
List<ContainerMount> volumes = null;
try {
volumes = getContainerVolumes(containerId);
} catch (Exception e) {
logger.error("Error on get container {} volumes. Volumes have not been removed", containerId);
}
// Remove container
dockerClient.removeContainer(containerId);
if (removeVolumes) {
this.removeVolumes(volumes);
}
}
Aggregations