Thursday, June 2, 2016
[1] Docker + Java
Below code segment can be used for pushing your Docker images to public docker registry / hub.
private StringBuffer output = new StringBuffer();
private String gitPush(String command) {
Process process;
try {
process = Runtime.getRuntime().exec(command);
process.waitFor();
BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
output.append(line + "\n");
}
} catch (Exception e) {
e.printStackTrace();
}
return output.toString();
}
Build Doker image using fabric8
---------------------------------------
public static boolean buildDockerImage(String dockerUrl, String image, String imageFolder)
throws InterruptedException, IOException {
Config config = new ConfigBuilder()
.withDockerUrl(dockerUrl)
.build();
DockerClient client = new DefaultDockerClient(config);
final CountDownLatch buildDone = new CountDownLatch(1);
OutputHandle handle = client.image().build()
.withRepositoryName(image)
.usingListener(new EventListener() {
@Override
public void onSuccess(String message) {
log.info("Success:" + message);
buildDone.countDown();
}
@Override
public void onError(String messsage) {
log.error("Failure:" + messsage);
buildDone.countDown();
}
@Override
public void onEvent(String event) {
log.info("Success:" + event);
}
})
.fromFolder(imageFolder);
buildDone.await();
handle.close();
client.close();
return true;
}
Subscribe to:
Post Comments (Atom)
Can you please give me real example for the inputs "dockerURL", and "image"
ReplyDeleteThank you,
Kavindu