-
Notifications
You must be signed in to change notification settings - Fork 2
EasyContainer
Karl "Khazrak" Andersson edited this page Jun 15, 2017
·
1 revision
Since the classes are 1-to-1 binding of Docker Remote API (#LINK) JDocker has a wrapper-class to make it more useable.
EasyContainer makes ContainerRequest a little less complicated.
Code Example:
//Mutable container request object
EasyContainer129 easyContainer = new EasyContainer129("mongo");
//Publish port on the host
easyContainer.addPublishPort("0.0.0.0",13377,8080);
Path host = Paths.get("/tmp/vol");
Path inContainer = Paths.get("/data");
//Adding a host volume
easyContainer.addHostVolume(host, inContainer);
//Setting CMD
easyContainer.cmd("ls -la");
//Setting --net
easyContainer.net("test-net");
//Containers name
easyContainer.name("container-name");
//Getting the builder-object for all the stuff EasyContainer does not support
easyContainer.getRequestBuilder().label("my_label","my_value");
//Get Immutable request
ContainerCreationRequest129 containerCreationRequest = easyContainer.buildRequest();
//Create client
DockerClient client = new DefaultDockerClient129();
//Create Container and get the ID from Docker server
String id = client.createContainer(containerCreationRequest);
//Start the container
client.start(id); // or client.start("container-name");
Since it would take to much time to make everything easy (all the settings and properties) you can get the "raw" ContainerRequestBuilder-object to set the values that EasyContainer doesn't help you with. HOWEVER when finished, use EasyContainer's build-method since some values are set in the last step (like aliases).