@Test @Ignore("Require a running docker daemon") public void testProvision() throws Exception { dockerService.provision("test", "8101", "1099", "44444", "8181", false, null); }
@Override public void provision(String name, String sshPort, String jmxRmiPort, String jmxRmiRegistryPort, String httpPort, boolean copy, String url) throws Exception { pull("java", "8-jre-alpine", true, url); File karafBase = new File(System.getProperty("karaf.base")); File containerStorage; if (copy) { containerStorage = new File(storageLocation, name); containerStorage.mkdirs(); copy(karafBase, containerStorage); makeFileExecutable(new File(containerStorage, "bin/karaf")); makeFileExecutable(new File(containerStorage, "bin/client")); makeFileExecutable(new File(containerStorage, "bin/inc")); makeFileExecutable(new File(containerStorage, "bin/instance")); makeFileExecutable(new File(containerStorage, "bin/setenv")); makeFileExecutable(new File(containerStorage, "bin/shell")); makeFileExecutable(new File(containerStorage, "bin/start")); makeFileExecutable(new File(containerStorage, "bin/status")); makeFileExecutable(new File(containerStorage, "bin/stop")); } else { containerStorage = karafBase; } DockerClient dockerClient = new DockerClient(url); ContainerConfig config = new ContainerConfig(); config.setTty(true); config.setAttachStdout(true); config.setAttachStderr(true); config.setAttachStdin(true); config.setImage("java:8-jre-alpine"); config.setHostname(""); config.setUser(""); config.setCmd(new String[]{ "/opt/apache-karaf/bin/karaf" }); config.setWorkingDir(""); config.setOpenStdin(true); config.setStdinOnce(true); Map<String, Map<String, String>> exposedPorts = new HashMap<>(); exposedPorts.put("8101/tcp", new HashMap<>()); exposedPorts.put("1099/tcp", new HashMap<>()); exposedPorts.put("44444/tcp", new HashMap<>()); exposedPorts.put("8181/tcp", new HashMap<>()); config.setExposedPorts(exposedPorts); HostConfig hostConfig = new HostConfig(); hostConfig.setPrivileged(false); hostConfig.setPublishAllPorts(false); hostConfig.setBinds(new String[]{containerStorage.getAbsolutePath() + ":/opt/apache-karaf"}); hostConfig.setNetworkMode("bridge"); hostConfig.setLxcConf(new String[]{}); Map<String, List<HostPortBinding>> portBindings = new HashMap<>(); List<HostPortBinding> sshPortBindings = new ArrayList<>(); HostPortBinding sshPortBinding = new HostPortBinding(); sshPortBinding.setHostIp(""); sshPortBinding.setHostPort(sshPort); sshPortBindings.add(sshPortBinding); portBindings.put("8101/tcp", sshPortBindings); List<HostPortBinding> jmxPortBindings = new ArrayList<>(); HostPortBinding jmxPortBinding = new HostPortBinding(); jmxPortBinding.setHostIp(""); jmxPortBinding.setHostPort(jmxRmiPort); jmxPortBindings.add(jmxPortBinding); portBindings.put("1099/tcp", jmxPortBindings); List<HostPortBinding> jmxRegistryPortBindings = new ArrayList<>(); HostPortBinding jmxRegistryPortBinding = new HostPortBinding(); jmxRegistryPortBinding.setHostIp(""); jmxRegistryPortBinding.setHostPort(jmxRmiRegistryPort); jmxRegistryPortBindings.add(jmxRegistryPortBinding); portBindings.put("44444/tcp", jmxRegistryPortBindings); List<HostPortBinding> httpPortBindings = new ArrayList<>(); HostPortBinding httpPortBinding = new HostPortBinding(); httpPortBinding.setHostIp(""); httpPortBinding.setHostPort(httpPort); httpPortBindings.add(httpPortBinding); portBindings.put("8181/tcp", httpPortBindings); hostConfig.setPortBindings(portBindings); config.setHostConfig(hostConfig); dockerClient.create(config, name); }
DockerServiceImpl implements DockerService { @Override public void provision(String name, String sshPort, String jmxRmiPort, String jmxRmiRegistryPort, String httpPort, boolean copy, String url) throws Exception { pull("java", "8-jre-alpine", true, url); File karafBase = new File(System.getProperty("karaf.base")); File containerStorage; if (copy) { containerStorage = new File(storageLocation, name); containerStorage.mkdirs(); copy(karafBase, containerStorage); makeFileExecutable(new File(containerStorage, "bin/karaf")); makeFileExecutable(new File(containerStorage, "bin/client")); makeFileExecutable(new File(containerStorage, "bin/inc")); makeFileExecutable(new File(containerStorage, "bin/instance")); makeFileExecutable(new File(containerStorage, "bin/setenv")); makeFileExecutable(new File(containerStorage, "bin/shell")); makeFileExecutable(new File(containerStorage, "bin/start")); makeFileExecutable(new File(containerStorage, "bin/status")); makeFileExecutable(new File(containerStorage, "bin/stop")); } else { containerStorage = karafBase; } DockerClient dockerClient = new DockerClient(url); ContainerConfig config = new ContainerConfig(); config.setTty(true); config.setAttachStdout(true); config.setAttachStderr(true); config.setAttachStdin(true); config.setImage("java:8-jre-alpine"); config.setHostname(""); config.setUser(""); config.setCmd(new String[]{ "/opt/apache-karaf/bin/karaf" }); config.setWorkingDir(""); config.setOpenStdin(true); config.setStdinOnce(true); Map<String, Map<String, String>> exposedPorts = new HashMap<>(); exposedPorts.put("8101/tcp", new HashMap<>()); exposedPorts.put("1099/tcp", new HashMap<>()); exposedPorts.put("44444/tcp", new HashMap<>()); exposedPorts.put("8181/tcp", new HashMap<>()); config.setExposedPorts(exposedPorts); HostConfig hostConfig = new HostConfig(); hostConfig.setPrivileged(false); hostConfig.setPublishAllPorts(false); hostConfig.setBinds(new String[]{containerStorage.getAbsolutePath() + ":/opt/apache-karaf"}); hostConfig.setNetworkMode("bridge"); hostConfig.setLxcConf(new String[]{}); Map<String, List<HostPortBinding>> portBindings = new HashMap<>(); List<HostPortBinding> sshPortBindings = new ArrayList<>(); HostPortBinding sshPortBinding = new HostPortBinding(); sshPortBinding.setHostIp(""); sshPortBinding.setHostPort(sshPort); sshPortBindings.add(sshPortBinding); portBindings.put("8101/tcp", sshPortBindings); List<HostPortBinding> jmxPortBindings = new ArrayList<>(); HostPortBinding jmxPortBinding = new HostPortBinding(); jmxPortBinding.setHostIp(""); jmxPortBinding.setHostPort(jmxRmiPort); jmxPortBindings.add(jmxPortBinding); portBindings.put("1099/tcp", jmxPortBindings); List<HostPortBinding> jmxRegistryPortBindings = new ArrayList<>(); HostPortBinding jmxRegistryPortBinding = new HostPortBinding(); jmxRegistryPortBinding.setHostIp(""); jmxRegistryPortBinding.setHostPort(jmxRmiRegistryPort); jmxRegistryPortBindings.add(jmxRegistryPortBinding); portBindings.put("44444/tcp", jmxRegistryPortBindings); List<HostPortBinding> httpPortBindings = new ArrayList<>(); HostPortBinding httpPortBinding = new HostPortBinding(); httpPortBinding.setHostIp(""); httpPortBinding.setHostPort(httpPort); httpPortBindings.add(httpPortBinding); portBindings.put("8181/tcp", httpPortBindings); hostConfig.setPortBindings(portBindings); config.setHostConfig(hostConfig); dockerClient.create(config, name); } }
DockerServiceImpl implements DockerService { @Override public void provision(String name, String sshPort, String jmxRmiPort, String jmxRmiRegistryPort, String httpPort, boolean copy, String url) throws Exception { pull("java", "8-jre-alpine", true, url); File karafBase = new File(System.getProperty("karaf.base")); File containerStorage; if (copy) { containerStorage = new File(storageLocation, name); containerStorage.mkdirs(); copy(karafBase, containerStorage); makeFileExecutable(new File(containerStorage, "bin/karaf")); makeFileExecutable(new File(containerStorage, "bin/client")); makeFileExecutable(new File(containerStorage, "bin/inc")); makeFileExecutable(new File(containerStorage, "bin/instance")); makeFileExecutable(new File(containerStorage, "bin/setenv")); makeFileExecutable(new File(containerStorage, "bin/shell")); makeFileExecutable(new File(containerStorage, "bin/start")); makeFileExecutable(new File(containerStorage, "bin/status")); makeFileExecutable(new File(containerStorage, "bin/stop")); } else { containerStorage = karafBase; } DockerClient dockerClient = new DockerClient(url); ContainerConfig config = new ContainerConfig(); config.setTty(true); config.setAttachStdout(true); config.setAttachStderr(true); config.setAttachStdin(true); config.setImage("java:8-jre-alpine"); config.setHostname(""); config.setUser(""); config.setCmd(new String[]{ "/opt/apache-karaf/bin/karaf" }); config.setWorkingDir(""); config.setOpenStdin(true); config.setStdinOnce(true); Map<String, Map<String, String>> exposedPorts = new HashMap<>(); exposedPorts.put("8101/tcp", new HashMap<>()); exposedPorts.put("1099/tcp", new HashMap<>()); exposedPorts.put("44444/tcp", new HashMap<>()); exposedPorts.put("8181/tcp", new HashMap<>()); config.setExposedPorts(exposedPorts); HostConfig hostConfig = new HostConfig(); hostConfig.setPrivileged(false); hostConfig.setPublishAllPorts(false); hostConfig.setBinds(new String[]{containerStorage.getAbsolutePath() + ":/opt/apache-karaf"}); hostConfig.setNetworkMode("bridge"); hostConfig.setLxcConf(new String[]{}); Map<String, List<HostPortBinding>> portBindings = new HashMap<>(); List<HostPortBinding> sshPortBindings = new ArrayList<>(); HostPortBinding sshPortBinding = new HostPortBinding(); sshPortBinding.setHostIp(""); sshPortBinding.setHostPort(sshPort); sshPortBindings.add(sshPortBinding); portBindings.put("8101/tcp", sshPortBindings); List<HostPortBinding> jmxPortBindings = new ArrayList<>(); HostPortBinding jmxPortBinding = new HostPortBinding(); jmxPortBinding.setHostIp(""); jmxPortBinding.setHostPort(jmxRmiPort); jmxPortBindings.add(jmxPortBinding); portBindings.put("1099/tcp", jmxPortBindings); List<HostPortBinding> jmxRegistryPortBindings = new ArrayList<>(); HostPortBinding jmxRegistryPortBinding = new HostPortBinding(); jmxRegistryPortBinding.setHostIp(""); jmxRegistryPortBinding.setHostPort(jmxRmiRegistryPort); jmxRegistryPortBindings.add(jmxRegistryPortBinding); portBindings.put("44444/tcp", jmxRegistryPortBindings); List<HostPortBinding> httpPortBindings = new ArrayList<>(); HostPortBinding httpPortBinding = new HostPortBinding(); httpPortBinding.setHostIp(""); httpPortBinding.setHostPort(httpPort); httpPortBindings.add(httpPortBinding); portBindings.put("8181/tcp", httpPortBindings); hostConfig.setPortBindings(portBindings); config.setHostConfig(hostConfig); dockerClient.create(config, name); }  }
DockerServiceImpl implements DockerService { @Override public void provision(String name, String sshPort, String jmxRmiPort, String jmxRmiRegistryPort, String httpPort, boolean copy, String url) throws Exception { pull("java", "8-jre-alpine", true, url); File karafBase = new File(System.getProperty("karaf.base")); File containerStorage; if (copy) { containerStorage = new File(storageLocation, name); containerStorage.mkdirs(); copy(karafBase, containerStorage); makeFileExecutable(new File(containerStorage, "bin/karaf")); makeFileExecutable(new File(containerStorage, "bin/client")); makeFileExecutable(new File(containerStorage, "bin/inc")); makeFileExecutable(new File(containerStorage, "bin/instance")); makeFileExecutable(new File(containerStorage, "bin/setenv")); makeFileExecutable(new File(containerStorage, "bin/shell")); makeFileExecutable(new File(containerStorage, "bin/start")); makeFileExecutable(new File(containerStorage, "bin/status")); makeFileExecutable(new File(containerStorage, "bin/stop")); } else { containerStorage = karafBase; } DockerClient dockerClient = new DockerClient(url); ContainerConfig config = new ContainerConfig(); config.setTty(true); config.setAttachStdout(true); config.setAttachStderr(true); config.setAttachStdin(true); config.setImage("java:8-jre-alpine"); config.setHostname(""); config.setUser(""); config.setCmd(new String[]{ "/opt/apache-karaf/bin/karaf" }); config.setWorkingDir(""); config.setOpenStdin(true); config.setStdinOnce(true); Map<String, Map<String, String>> exposedPorts = new HashMap<>(); exposedPorts.put("8101/tcp", new HashMap<>()); exposedPorts.put("1099/tcp", new HashMap<>()); exposedPorts.put("44444/tcp", new HashMap<>()); exposedPorts.put("8181/tcp", new HashMap<>()); config.setExposedPorts(exposedPorts); HostConfig hostConfig = new HostConfig(); hostConfig.setPrivileged(false); hostConfig.setPublishAllPorts(false); hostConfig.setBinds(new String[]{containerStorage.getAbsolutePath() + ":/opt/apache-karaf"}); hostConfig.setNetworkMode("bridge"); hostConfig.setLxcConf(new String[]{}); Map<String, List<HostPortBinding>> portBindings = new HashMap<>(); List<HostPortBinding> sshPortBindings = new ArrayList<>(); HostPortBinding sshPortBinding = new HostPortBinding(); sshPortBinding.setHostIp(""); sshPortBinding.setHostPort(sshPort); sshPortBindings.add(sshPortBinding); portBindings.put("8101/tcp", sshPortBindings); List<HostPortBinding> jmxPortBindings = new ArrayList<>(); HostPortBinding jmxPortBinding = new HostPortBinding(); jmxPortBinding.setHostIp(""); jmxPortBinding.setHostPort(jmxRmiPort); jmxPortBindings.add(jmxPortBinding); portBindings.put("1099/tcp", jmxPortBindings); List<HostPortBinding> jmxRegistryPortBindings = new ArrayList<>(); HostPortBinding jmxRegistryPortBinding = new HostPortBinding(); jmxRegistryPortBinding.setHostIp(""); jmxRegistryPortBinding.setHostPort(jmxRmiRegistryPort); jmxRegistryPortBindings.add(jmxRegistryPortBinding); portBindings.put("44444/tcp", jmxRegistryPortBindings); List<HostPortBinding> httpPortBindings = new ArrayList<>(); HostPortBinding httpPortBinding = new HostPortBinding(); httpPortBinding.setHostIp(""); httpPortBinding.setHostPort(httpPort); httpPortBindings.add(httpPortBinding); portBindings.put("8181/tcp", httpPortBindings); hostConfig.setPortBindings(portBindings); config.setHostConfig(hostConfig); dockerClient.create(config, name); }  File getStorageLocation(); void setStorageLocation(File storageLocation); @Override List<Container> ps(boolean showAll, String url); @Override Info info(String url); @Override Version version(String url); @Override void create(String name, String url); @Override void create(String name, String url, ContainerConfig config); @Override void provision(String name, String sshPort, String jmxRmiPort, String jmxRmiRegistryPort, String httpPort, boolean copy, String url); @Override void start(String name, String url); @Override void stop(String name, int timeToWait, String url); @Override void restart(String name, int timeToWait, String url); @Override void kill(String name, String signal, String url); @Override void pause(String name, String url); @Override void unpause(String name, String url); @Override void rename(String name, String newName, String url); @Override void rm(String name, boolean removeVolumes, boolean force, String url); @Override String logs(String name, boolean stdout, boolean stderr, boolean timestamps, boolean details, String url); @Override Top top(String name, String url); @Override void commit(String name, String repo, String tag, String message, String url); @Override List<Image> images(String url); @Override void pull(String image, String tag, boolean verbose, String url); @Override List<ImageSearch> search(String term, String url); @Override Container inspect(String name, String url); @Override void push(String image, String tag, boolean verbose, String url); @Override List<ImageHistory> history(String image, String url); @Override void tag(String image, String repo, String tag, String url); @Override void rmi(String image, boolean force, boolean noprune, String url); }
DockerServiceImpl implements DockerService { @Override public void provision(String name, String sshPort, String jmxRmiPort, String jmxRmiRegistryPort, String httpPort, boolean copy, String url) throws Exception { pull("java", "8-jre-alpine", true, url); File karafBase = new File(System.getProperty("karaf.base")); File containerStorage; if (copy) { containerStorage = new File(storageLocation, name); containerStorage.mkdirs(); copy(karafBase, containerStorage); makeFileExecutable(new File(containerStorage, "bin/karaf")); makeFileExecutable(new File(containerStorage, "bin/client")); makeFileExecutable(new File(containerStorage, "bin/inc")); makeFileExecutable(new File(containerStorage, "bin/instance")); makeFileExecutable(new File(containerStorage, "bin/setenv")); makeFileExecutable(new File(containerStorage, "bin/shell")); makeFileExecutable(new File(containerStorage, "bin/start")); makeFileExecutable(new File(containerStorage, "bin/status")); makeFileExecutable(new File(containerStorage, "bin/stop")); } else { containerStorage = karafBase; } DockerClient dockerClient = new DockerClient(url); ContainerConfig config = new ContainerConfig(); config.setTty(true); config.setAttachStdout(true); config.setAttachStderr(true); config.setAttachStdin(true); config.setImage("java:8-jre-alpine"); config.setHostname(""); config.setUser(""); config.setCmd(new String[]{ "/opt/apache-karaf/bin/karaf" }); config.setWorkingDir(""); config.setOpenStdin(true); config.setStdinOnce(true); Map<String, Map<String, String>> exposedPorts = new HashMap<>(); exposedPorts.put("8101/tcp", new HashMap<>()); exposedPorts.put("1099/tcp", new HashMap<>()); exposedPorts.put("44444/tcp", new HashMap<>()); exposedPorts.put("8181/tcp", new HashMap<>()); config.setExposedPorts(exposedPorts); HostConfig hostConfig = new HostConfig(); hostConfig.setPrivileged(false); hostConfig.setPublishAllPorts(false); hostConfig.setBinds(new String[]{containerStorage.getAbsolutePath() + ":/opt/apache-karaf"}); hostConfig.setNetworkMode("bridge"); hostConfig.setLxcConf(new String[]{}); Map<String, List<HostPortBinding>> portBindings = new HashMap<>(); List<HostPortBinding> sshPortBindings = new ArrayList<>(); HostPortBinding sshPortBinding = new HostPortBinding(); sshPortBinding.setHostIp(""); sshPortBinding.setHostPort(sshPort); sshPortBindings.add(sshPortBinding); portBindings.put("8101/tcp", sshPortBindings); List<HostPortBinding> jmxPortBindings = new ArrayList<>(); HostPortBinding jmxPortBinding = new HostPortBinding(); jmxPortBinding.setHostIp(""); jmxPortBinding.setHostPort(jmxRmiPort); jmxPortBindings.add(jmxPortBinding); portBindings.put("1099/tcp", jmxPortBindings); List<HostPortBinding> jmxRegistryPortBindings = new ArrayList<>(); HostPortBinding jmxRegistryPortBinding = new HostPortBinding(); jmxRegistryPortBinding.setHostIp(""); jmxRegistryPortBinding.setHostPort(jmxRmiRegistryPort); jmxRegistryPortBindings.add(jmxRegistryPortBinding); portBindings.put("44444/tcp", jmxRegistryPortBindings); List<HostPortBinding> httpPortBindings = new ArrayList<>(); HostPortBinding httpPortBinding = new HostPortBinding(); httpPortBinding.setHostIp(""); httpPortBinding.setHostPort(httpPort); httpPortBindings.add(httpPortBinding); portBindings.put("8181/tcp", httpPortBindings); hostConfig.setPortBindings(portBindings); config.setHostConfig(hostConfig); dockerClient.create(config, name); }  File getStorageLocation(); void setStorageLocation(File storageLocation); @Override List<Container> ps(boolean showAll, String url); @Override Info info(String url); @Override Version version(String url); @Override void create(String name, String url); @Override void create(String name, String url, ContainerConfig config); @Override void provision(String name, String sshPort, String jmxRmiPort, String jmxRmiRegistryPort, String httpPort, boolean copy, String url); @Override void start(String name, String url); @Override void stop(String name, int timeToWait, String url); @Override void restart(String name, int timeToWait, String url); @Override void kill(String name, String signal, String url); @Override void pause(String name, String url); @Override void unpause(String name, String url); @Override void rename(String name, String newName, String url); @Override void rm(String name, boolean removeVolumes, boolean force, String url); @Override String logs(String name, boolean stdout, boolean stderr, boolean timestamps, boolean details, String url); @Override Top top(String name, String url); @Override void commit(String name, String repo, String tag, String message, String url); @Override List<Image> images(String url); @Override void pull(String image, String tag, boolean verbose, String url); @Override List<ImageSearch> search(String term, String url); @Override Container inspect(String name, String url); @Override void push(String image, String tag, boolean verbose, String url); @Override List<ImageHistory> history(String image, String url); @Override void tag(String image, String repo, String tag, String url); @Override void rmi(String image, boolean force, boolean noprune, String url);  }