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(); }
/** * 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(); }
public void restart(String id) { DockerClient cli = docker.getDockerClient(); if (cli == null) return; cli.restartContainerCmd(id).exec(); }
public void containerStart(String id) { DockerClient cli = docker.getDockerClient(); if (cli == null) return; cli.startContainerCmd(id); }
public void kill(String id) { DockerClient cli = docker.getDockerClient(); if (cli == null) return; cli.killContainerCmd(id).exec(); }
public void commit(String id) { DockerClient cli = docker.getDockerClient(); if (cli == null) return; cli.commitCmd(id).exec(); }
public void unPause(String id) { DockerClient cli = docker.getDockerClient(); if (cli == null) return; cli.unpauseContainerCmd(id).exec(); }
public void delete(String id) { DockerClient cli = docker.getDockerClient(); if (cli == null) return; cli.removeContainerCmd(id).exec(); }
public InspectContainerResponse info(String id) { DockerClient cli = docker.getDockerClient(); if (cli == null) return null; return cli.inspectContainerCmd(id).exec(); }
public List<Container> list() { DockerClient cli = docker.getDockerClient(); if (cli == null) return new ArrayList<Container>(); return cli.listContainersCmd().withShowAll(true).exec(); }
public void tarImport(String name, InputStream input) { DockerCommand icci = new ImportContainerCmdImpl(docker.getDockerPath()); icci.exec(name, input); }
public InputStream export(String id) { DockerCommand cmd = new ExportContainerCmdImpl(docker.getDockerPath()); return (InputStream) cmd.exec(id); }