Skip to content

nginate/commons-docker

Repository files navigation

Overview

Official java docker client is a bit creepy when talking about working with dtos and asynchronous. This lib was made to hide boilerplate when synchronizing container states and converting client dto classes.

Build status

What's there in this bundle?

  • Docker client

Wrapper for official docker client. Allows passing dto with null fields (official client for some reason has assertions in field setters, checking against null values). Also hides most of common request creation code.

    NDockerClient client = new NDockerClient(dockerClient);
    client.startContainer("id");
    
    // vanilla client
    DockerClient client = ...
    client.startContainerCmd(containerId).exec();
  • Docker container

All container commands require passing container id, so it could be encapsulated in another wrapper.

    DockerContainer service1 = new DockerContainer(client, "id");
    DockerContainer service2 = new DockerContainer(client, "id2");
    
    service1.start();
    service2.start();
    
    service2.stop();
    service2.printLogs();
    
    // vanilla client
    DockerClient client = ...
    String service1Id = ...
    String service2Id = ...
        
    client.startContainerCmd(service1Id).exec();
    client.startContainerCmd(service2Id).exec();
    
    client.stopContainerCmd(service2Id).exec();
    client.logContainerCmd(service2Id)
                    .withStdOut()
                    .withStdErr()
                    .exec(new DockerLogger(logConsumer))
                    .awaitCompletion();

License

WTFPL