jclouds-docker is a local cloud provider modelled on docker. Similar to other jclouds supported providers, it supports the same portable abstractions offered by jclouds.

jclouds docker architecture

In order to mimic the behavior of the nodes that jclouds is able to manage, we need to make the Docker containers similar to any other VM. Fortunately, to have that is not much work: the only prerequisite is that the node needs to be ssh’able. This involves dockerizing an SSH daemon service.

Give it a try!

// get a context with docker that offers the portable ComputeService api
ComputeServiceContext context = ContextBuilder.newBuilder("docker")
                      .credentials(email, password)
                      .modules(ImmutableSet.<Module> of(new Log4JLoggingModule(),
                                                        new SshjSshClientModule()))
ComputeService client = context.getComputeService();

String sshableImageId = "your-sshable-image-id"; // this can be obtained using `docker images --no-trunc` command
Template template = client.templateBuilder().imageId(sshableImageId).build();

// run a couple nodes accessible via group container
Set<? extends NodeMetadata> nodes = client.runNodesInGroup("container", 2, template);

// release resources

As for any other jclouds API, this code will create for you 2 nodes in the group container using the provided template. The only (big) difference is that jclouds-docker will spin up 2 docker containers for you, instead of being 2 plain-old virtual machines, as it generally happens for the other cloud providers.