Java Code Examples for com.github.dockerjava.api.command.CreateContainerCmd#withCmd()
The following examples show how to use
com.github.dockerjava.api.command.CreateContainerCmd#withCmd() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticsearchAuthSystemTest.java From elasticsearch with Apache License 2.0 | 6 votes |
@Override protected CreateContainerCmd dockerCommand() { CreateContainerCmd createContainerCmd = super.dockerCommand(); createContainerCmd.withBinds(new Bind(SECRET_FOLDER, new Volume(SECRET_FOLDER))); createContainerCmd.withCmd( ZookeeperCLIParameter.ZOOKEEPER_MESOS_URL, getZookeeperMesosUrl(), ElasticsearchCLIParameter.ELASTICSEARCH_NODES, Integer.toString(TEST_CONFIG.getElasticsearchNodesCount()), org.apache.mesos.elasticsearch.scheduler.Configuration.ELASTICSEARCH_RAM, "256", org.apache.mesos.elasticsearch.scheduler.Configuration.ELASTICSEARCH_DISK, "10", org.apache.mesos.elasticsearch.scheduler.Configuration.USE_IP_ADDRESS, "true", org.apache.mesos.elasticsearch.scheduler.Configuration.FRAMEWORK_ROLE, "testRole", org.apache.mesos.elasticsearch.scheduler.Configuration.FRAMEWORK_PRINCIPAL, "testRole", org.apache.mesos.elasticsearch.scheduler.Configuration.FRAMEWORK_SECRET_PATH, SECRET_FOLDER + FRAMEWORKPASSWD, org.apache.mesos.elasticsearch.scheduler.Configuration.ELASTICSEARCH_CPU, "0.2" ); return createContainerCmd; }
Example 2
Source File: DockerComputerJNLPConnector.java From docker-plugin with MIT License | 6 votes |
@Override public void beforeContainerCreated(DockerAPI api, String workdir, CreateContainerCmd cmd) throws IOException, InterruptedException { final String effectiveJenkinsUrl = StringUtils.isEmpty(jenkinsUrl) ? Jenkins.getInstance().getRootUrl() : jenkinsUrl; final String nodeName = DockerTemplate.getNodeNameFromContainerConfig(cmd); final String secret = JnlpSlaveAgentProtocol.SLAVE_SECRET.mac(nodeName); final EnvVars knownVariables = calculateVariablesForVariableSubstitution(nodeName, secret, jnlpLauncher.tunnel, effectiveJenkinsUrl); final String configuredArgString = getEntryPointArgumentsString(); final String effectiveConfiguredArgString = StringUtils.isNotBlank(configuredArgString) ? configuredArgString : DEFAULT_ENTRY_POINT_ARGUMENTS; final String resolvedArgString = Util.replaceMacro(effectiveConfiguredArgString, knownVariables); final String[] resolvedArgs = splitAndFilterEmpty(resolvedArgString, "\n"); cmd.withCmd(resolvedArgs); String vmargs = jnlpLauncher.vmargs; if (StringUtils.isNotBlank(vmargs)) { DockerEnvUtils.addEnvToCmd("JAVA_OPT", vmargs.trim(), cmd); } if (StringUtils.isNotBlank(user)) { cmd.withUser(user); } }
Example 3
Source File: DockerComputerSSHConnector.java From docker-plugin with MIT License | 6 votes |
@Override public void beforeContainerCreated(DockerAPI api, String workdir, CreateContainerCmd cmd) throws IOException, InterruptedException { // TODO define a strategy for SSHD process configuration so we support more than openssh's sshd final String[] cmdArray = cmd.getCmd(); if (cmdArray == null || cmdArray.length == 0) { if (sshKeyStrategy.getInjectedKey() != null) { cmd.withCmd("/usr/sbin/sshd", "-D", "-p", String.valueOf(port), // override sshd_config to force retrieval of InstanceIdentity public for as authentication "-o", "AuthorizedKeysCommand=/root/authorized_key", "-o", "AuthorizedKeysCommandUser=root" ); } else { cmd.withCmd("/usr/sbin/sshd", "-D", "-p", String.valueOf(port)); } } cmd.withPortSpecs(port+"/tcp"); final PortBinding sshPortBinding = PortBinding.parse(":" + port); final Ports portBindings = cmd.getPortBindings(); if(portBindings != null) { portBindings.add(sshPortBinding); cmd.withPortBindings(portBindings); } else { cmd.withPortBindings(sshPortBinding); } cmd.withExposedPorts(ExposedPort.parse(port+"/tcp")); }
Example 4
Source File: CreateContainerWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 4 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { Map<String, Object> results = new HashMap<String, Object>(); try { RequiredParameterValidator.validate(this.getClass(), workItem); String containerName = (String) workItem.getParameter("ContainerName"); String containerImageName = (String) workItem.getParameter("ContainerImageName"); String containerCommand = (String) workItem.getParameter("ContainerCommand"); String containerHostName = (String) workItem.getParameter("ContainerHostName"); String containerEnv = (String) workItem.getParameter("ContainerEnv"); String containerPortBindings = (String) workItem.getParameter("ContainerPortBindings"); String containerBinds = (String) workItem.getParameter("ContainerBinds"); if (dockerClient == null) { DockerClientConnector connector = new DockerClientConnector(); dockerClient = connector.getDockerClient(); } CreateContainerCmd createContainerCmd = dockerClient.createContainerCmd(containerImageName).withName(containerName); if (containerCommand != null) { createContainerCmd = createContainerCmd.withCmd(containerCommand); } if (containerHostName != null) { createContainerCmd = createContainerCmd.withHostName(containerHostName); } if (containerEnv != null) { createContainerCmd = createContainerCmd.withEnv(containerEnv); } if (containerPortBindings != null) { createContainerCmd = createContainerCmd.withPortBindings(PortBinding.parse(containerPortBindings)); } if (containerBinds != null) { createContainerCmd = createContainerCmd.withBinds(Bind.parse(containerBinds)); } CreateContainerResponse container = createContainerCmd.exec(); if (container != null && container.getId() != null) { results.put(RESULTS_DOCUMENT, container.getId()); } workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { logger.error("Unable to create container: " + e.getMessage()); handleException(e); } }
Example 5
Source File: DockerizedExecHandle.java From gradle-dockerized-test-plugin with Apache License 2.0 | 4 votes |
public Process runContainer() { try { DockerClient client = testExtension.getClient(); CreateContainerCmd createCmd = client.createContainerCmd(testExtension.getImage().toString()) .withTty(false) .withStdinOpen(true) .withStdInOnce(true) .withWorkingDir(directory.getAbsolutePath()); createCmd.withEnv(getEnv()); String user = testExtension.getUser(); if (user != null) createCmd.withUser(user); bindVolumes(createCmd); List<String> cmdLine = new ArrayList<String>(); cmdLine.add(command); cmdLine.addAll(arguments); createCmd.withCmd(cmdLine); invokeIfNotNull(testExtension.getBeforeContainerCreate(), createCmd, client); String containerId = createCmd.exec().getId(); invokeIfNotNull(testExtension.getAfterContainerCreate(), containerId, client); maybeCopyJvmOptionFile(containerId, client); invokeIfNotNull(testExtension.getBeforeContainerStart(), containerId, client); client.startContainerCmd(containerId).exec(); invokeIfNotNull(testExtension.getAfterContainerStart(), containerId, client); if (!client.inspectContainerCmd(containerId).exec().getState().getRunning()) { throw new RuntimeException("Container "+containerId+" not running!"); } Process proc = new DockerizedProcess(client, containerId, testExtension.getAfterContainerStop()); return proc; } catch (Exception e) { LOGGER.error("Failed to create container " + displayName, new RuntimeException(e)); throw new RuntimeException(e); } }