Listing Docker Containers with Nashorn

Nashorn is a convenient REST-service client:

#!/usr/bin/jjs -fv
var host = "DOCKER_HOST"
var dockerUri="http://${host}:5555/containers/json";
var command = "curl ${dockerUri}";
var containers = JSON.parse($OUT);
for each(container in containers){
	print("${container.Image} 	 ${container.Names[0]}	 ${container.Status}");

See also:

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


And if you are not sure that curl is present, and remember that you've got the full power of the JRE at your fingertips you could replace the call to curl with something along:

function readUtf8Stream(url) {
var byteArray = Java.type("byte[]");
var inputStream = new;
var buffer = new byteArray(1024);
var read = 0;
var baos = new;
while((read = > 0) {
baos.write(buffer, 0, read);
return new java.lang.String(baos.toByteArray(), "UTF-8");

Posted by Matthias on January 22, 2015 at 06:35 PM CET #

The only problem with JJS is that it is unavailable until java 8 - and quite a bit of software doesn't relly work with java 8 - at least in companies I know :/

Posted by psychollek on January 26, 2015 at 10:50 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments