Khazrak / JDocker

Java Docker Client
Other
10 stars 2 forks source link

JDocker

Java Docker Client

Docker client in Java that uses tcp or socket. It mapps domain-objects to json and follow Docker Remote API. Currently only implemented API version 1.26 (Docker 1.13.1 & 17.03.0) (Earlier 1.24 but after refactoring the new baseline will be 1.26) A new structure have been implemented to make backwards compatibility better (new things will throw Exceptions if used on old API versions)

The client have support for tcp, unixsocket and Windows namedpipe (holy ship!), test of OSX socket will come (it might already work).

Most functions have recorded request-response (By Wiremock proxy to docker) and are used in unittest by Wiremock (files and mappings)

Setting up the client

Gradle:

compile 'com.github.khazrak:jdocker-client:2.0.0'

Maven:

<dependency>
    <groupId>com.github.khazrak</groupId>
    <artifactId>jdocker-client</artifactId>
    <version>2.0.0</version>
</dependency>

Remote Unsecure tcp

DockerClient client = new DefaultDockerClient126("http://127.0.0.1:4243");

Remote secure tcp

DockerClient client = new DefaultDockerClient126("https://127.0.0.1:2376", "/path/to/ssl/certs");

Unix socket/named Pipe

DockerClient client = new DefaultDockerClient126();

Wrapper classes (EasyContainer)

DockerClient client = new DefaultDockerClient126();

EasyContainer container = new EasyContainer("mongo");
container.net("my-net")
      .name("my-mongo")
      .addAlias("haha-mongo")
      .addPublishPort("0.0.0.0",1337,8080)
      .addVolume(Paths.get("/tmp"))
      .addVolume("my-vol", Paths.get("/my_volume"))
      .addHostVolume(Paths.get("/tmp/logs"), Paths.get("/var/log"))
      //.cmd("echo 'hello'")
      .addEnvVariable("key","value");

ContainerCreationRequest containerCreationRequest = container.buildRequest();

Map<String, List<HostPort>> portBindings = containerCreationRequest.getHostConfig().getPortBindings();

System.out.println(portBindings);

String id = client.createContainer(containerCreationRequest);
client.start(id);

client.close();

Building from source

You need to add these properties to your project:

ossrhUsername=null
ossrhPassword=null

Implemented

Containers

Images

Misc

Volumes

Networks

TODO

Container

Misc

More Custom Tests