Example #1
0
 public String log(String id) throws IOException {
   DockerClient cli = docker.getDockerClient();
   if (cli == null) return null;
   BufferedReader reader =
       new BufferedReader(
           new InputStreamReader(
               cli.logContainerCmd(id).withStdErr().withStdOut().withTimestamps().exec(),
               Constants.DEFAULT_ENCODING)); // bugfix: add stream to
   // cmd
   StringBuilder sb = new StringBuilder();
   String line = null;
   while ((line = reader.readLine()) != null) {
     sb.append(line).append("\n");
   }
   return sb.toString();
 }
Example #2
0
 /**
  * create a new container from a image, and run it after build completed
  *
  * @param image
  * @param name
  * @param cmd
  * @param ports
  */
 public void create(String image, String name, String cmd, String ports) {
   DockerClient cli = docker.getDockerClient();
   if (cli == null) return;
   CreateContainerCmd ccc = cli.createContainerCmd(image);
   ccc.withName(name);
   if (cmd != null && !"".equals(cmd)) ccc.withCmd(cmd);
   CreateContainerResponse ccr = ccc.exec();
   String id = ccr.getId();
   StartContainerCmd scc = cli.startContainerCmd(id);
   Ports portBindings = new Ports();
   String[] portPairs = ports.split(" ");
   for (String portPair : portPairs) {
     String[] localHost = portPair.split(":");
     if (localHost.length != 2) continue;
     ExposedPort ep = new ExposedPort("tcp", Integer.valueOf(localHost[0]));
     Binding binding = new Binding(Integer.valueOf(localHost[1]));
     portBindings.bind(ep, binding);
   }
   scc.withPortBindings(portBindings);
   scc.exec();
 }
Example #3
0
 public void restart(String id) {
   DockerClient cli = docker.getDockerClient();
   if (cli == null) return;
   cli.restartContainerCmd(id).exec();
 }
Example #4
0
 public void containerStart(String id) {
   DockerClient cli = docker.getDockerClient();
   if (cli == null) return;
   cli.startContainerCmd(id);
 }
Example #5
0
 public void kill(String id) {
   DockerClient cli = docker.getDockerClient();
   if (cli == null) return;
   cli.killContainerCmd(id).exec();
 }
Example #6
0
 public void commit(String id) {
   DockerClient cli = docker.getDockerClient();
   if (cli == null) return;
   cli.commitCmd(id).exec();
 }
Example #7
0
 public void unPause(String id) {
   DockerClient cli = docker.getDockerClient();
   if (cli == null) return;
   cli.unpauseContainerCmd(id).exec();
 }
Example #8
0
 public void delete(String id) {
   DockerClient cli = docker.getDockerClient();
   if (cli == null) return;
   cli.removeContainerCmd(id).exec();
 }
Example #9
0
 public InspectContainerResponse info(String id) {
   DockerClient cli = docker.getDockerClient();
   if (cli == null) return null;
   return cli.inspectContainerCmd(id).exec();
 }
Example #10
0
 public List<Container> list() {
   DockerClient cli = docker.getDockerClient();
   if (cli == null) return new ArrayList<Container>();
   return cli.listContainersCmd().withShowAll(true).exec();
 }
Example #11
0
 public void tarImport(String name, InputStream input) {
   DockerCommand icci = new ImportContainerCmdImpl(docker.getDockerPath());
   icci.exec(name, input);
 }
Example #12
0
 public InputStream export(String id) {
   DockerCommand cmd = new ExportContainerCmdImpl(docker.getDockerPath());
   return (InputStream) cmd.exec(id);
 }