forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Home
marcuslinke edited this page Sep 12, 2014
·
29 revisions
Detailed code examples can be found in the test cases
DockerClient dockerClient = new DockerClientImpl("http://localhost:2375");
Info info = dockerClient.infoCmd().exec();
System.out.print(info);
List<SearchItem> dockerSearch = dockerClient.searchImagesCmd("busybox").exec();
System.out.println("Search returned" + dockerSearch.toString());
ContainerCreateResponse container =
dockerClient.createContainerCmd("busybox")
.withCmd("touch", "/test")
.exec();
dockerClient.startContainerCmd(container.id).exec();
dockerClient.waitContainerCmd(container.id).exec();
dockerClient.stopContainerCmd(container.id).exec();
File baseDir = new File("~/kpelykh/docker/netcat");
InputStream response = dockerClient.buildImageCmd(baseDir).exec();
StringWriter logwriter = new StringWriter();
try {
LineIterator itr = IOUtils.lineIterator(response, "UTF-8");
while (itr.hasNext()) {
String line = itr.next();
logwriter.write(line);
LOG.info(line);
}
} finally {
IOUtils.closeQuietly(response);
}