Java Code Examples for com.github.dockerjava.api.command.CreateContainerCmd#withBinds()
The following examples show how to use
com.github.dockerjava.api.command.CreateContainerCmd#withBinds() .
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: DockerManager.java From flow-platform-x with Apache License 2.0 | 6 votes |
public String createAndStartContainer(Option option) { StringVars defaultEnv = new StringVars(4); defaultEnv.put(Variables.App.Url, serverUrl); defaultEnv.put(Variables.Agent.Token, ApiAuth.LocalTaskToken); defaultEnv.put(Variables.Agent.Workspace, "/ws/"); defaultEnv.put(Variables.Agent.PluginDir, "/ws/.plugins"); CreateContainerCmd createContainerCmd = client.createContainerCmd(option.image) .withEnv(defaultEnv.merge(option.inputs).toList()) .withCmd("/bin/bash", "-c", option.script); if (option.hasPlugin()) { createContainerCmd.withBinds( new Bind(option.pluginDir, new Volume("/ws/.plugins/" + option.plugin))); } CreateContainerResponse container = createContainerCmd.exec(); String containerId = container.getId(); client.startContainerCmd(container.getId()).exec(); log.debug("Container {} been started", containerId); return containerId; }
Example 2
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 3
Source File: BindVolumeCreateContainerPostProcessor.java From Dolphin with Apache License 2.0 | 5 votes |
@Override public void beforeCreateContainer(CreateContainerContext createContainerContext) { CreateContainerCmd createContainerCmd = createContainerContext.getCreateContainerCmd(); Bind bind = createBind(createContainerContext.getInstanceStartRequest()); createContainerCmd.withBinds(bind); }
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); } }