当前位置: 首页>>代码示例>>Java>>正文


Java CreateContainerCmd.exec方法代码示例

本文整理汇总了Java中com.github.dockerjava.api.command.CreateContainerCmd.exec方法的典型用法代码示例。如果您正苦于以下问题:Java CreateContainerCmd.exec方法的具体用法?Java CreateContainerCmd.exec怎么用?Java CreateContainerCmd.exec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.dockerjava.api.command.CreateContainerCmd的用法示例。


在下文中一共展示了CreateContainerCmd.exec方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createContainer

import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
private String createContainer(){
    ensureImage(imageName);

    CreateContainerCmd createContainerCmd = dockerClient
            .createContainerCmd(containerName)
            .withImage(imageName)

            .withCmd("sleep", "9999")
            .withLabels(label(containerName))
            .withName(containerName);

    if(bindings != null){
        createContainerCmd.withBinds(bindings);
    }
    CreateContainerResponse resp = createContainerCmd.exec();
    return resp.getId();
}
 
开发者ID:b-long,项目名称:jedi,代码行数:18,代码来源:JediDockerClient.java

示例2: startNode

import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
public void startNode(String id, BrowserType browserType, String nodeName, String imageId,
    String hubIp) {
  // Create node if not exist
  if (!existsContainer(nodeName)) {

    pullImageIfNecessary(imageId, false);

    log.debug("Creating container {}", nodeName);

    CreateContainerCmd createContainerCmd =
        getClient().createContainerCmd(imageId).withName(nodeName);

    // TODO make this port configurable
    createContainerCmd.withEnv(new String[] { "HUB_PORT_4444_TCP_ADDR=" + hubIp, "HUB_PORT_4444_TCP_PORT=4444" });

    createContainerCmd.exec();

    log.debug("Container {} started...", nodeName);

  } else {
    log.debug("Container {} already exists", nodeName);
  }

  // Start node if stopped
  startContainer(nodeName);
}
 
开发者ID:Kurento,项目名称:kurento-java,代码行数:27,代码来源:Docker.java

示例3: runContainer

import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
/**
 * for publishers/builders. Simply runs container in docker cloud
 */
public static String runContainer(DockerTemplateBase dockerTemplateBase,
                                  DockerClient dockerClient) {
    CreateContainerCmd containerConfig = dockerClient.createContainerCmd(dockerTemplateBase.getImage());

    dockerTemplateBase.fillContainerConfig(containerConfig);

    // create
    CreateContainerResponse response = containerConfig.exec();
    String containerId = response.getId();

    // start
    StartContainerCmd startCommand = dockerClient.startContainerCmd(containerId);
    startCommand.exec();

    return containerId;
}
 
开发者ID:jenkinsci,项目名称:docker-plugin,代码行数:20,代码来源:DockerCloud.java

示例4: startContainer

import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
private String startContainer(CreateContainerCmd cmd, DockerClient client) {
	CreateContainerResponse createResp = cmd.exec();
	StartContainerCmd startCmd = client.startContainerCmd(createResp.getId());
	try {
		startCmd.exec();
	} catch (Throwable t) {
		throw new ContainerException(createResp.getId(), t);
	}
	return startCmd.getContainerId();
}
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:11,代码来源:DefaultServiceBuilder.java

示例5: run

import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
@Override
public List<String> run(TestEnvironment testEnvironment) {
    String hostOsMountDir = System.getProperties().getProperty("buildDirectory");


    CreateContainerCmd containerBuilder = dockerClient.createContainerCmd(testEnvironment.getImage())
            .withBinds(new Bind(hostOsMountDir, new Volume(Constants.HAWKULAR_APM_AGENT_DIRECTORY),
                            AccessMode.ro, SELContext.shared),
                new Bind(scenarioDirectory, new Volume(Constants.HAWKULAR_APM_TEST_DIRECTORY),
                        AccessMode.ro, SELContext.shared))
            .withExtraHosts(Constants.HOST_ADDED_TO_ETC_HOSTS + ":" + apmBindAddress);

    if (userDefinedNetwork) {
        if (network == null) {
            throw new IllegalStateException("Create network before running environment");
        }
        containerBuilder.withNetworkMode(network.getName());
    }

    containerBuilder.withEnv(apmEnvVariables(testEnvironment.getType()));

    if (testEnvironment.isPull()) {
        log.info("Pulling image...");
        dockerClient.pullImageCmd(testEnvironment.getImage()).exec(new PullImageResultCallback()).awaitSuccess();
    }

    CreateContainerResponse containerResponse = containerBuilder.exec();
    log.info(String.format("Starting docker container: %s", containerResponse));

    try {
        dockerClient.startContainerCmd(containerResponse.getId()).exec();
    } catch (DockerException ex) {
        log.severe(String.format("Could not create or start docker container: %s", containerResponse));
        throw new EnvironmentException("Could not create or start docker container.", ex);
    }

    return Arrays.asList(containerResponse.getId());
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:39,代码来源:DockerImageExecutor.java

示例6: create

import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
@Override
public String create(String image, String name, String[] env, String[] linking) {
    DockerClient dockerClient = getClient();
    
    if (image == null  || image.trim().length() == 0) {
        LOGGER.error("Container's image name to create is empty");
        return null;
    }
    
    final CreateContainerCmd createContainerCmd = dockerClient.createContainerCmd(image)
            .withPublishAllPorts(true)
            .withAttachStdout(true)
            .withAttachStdin(true)
            .withAttachStdin(true)
            .withTty(true);
    if (linking != null) {
        final String linkName = linking[0];
        final String linkAlias = linking[1];
        final Link link = new Link(linkName, linkAlias);
        createContainerCmd.withLinks(link);
    }
    if (name != null && name.trim().length() > 0) createContainerCmd.withName(name);
    if (env != null && env.length > 0) createContainerCmd.withEnv(env);
    
    final CreateContainerResponse createContainerResponse = createContainerCmd.exec();
    final String id = createContainerResponse.getId();
    
    return id;
}
 
开发者ID:kiegroup,项目名称:kie-docker-ci,代码行数:30,代码来源:DockerServiceImpl.java

示例7: createContainer

import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
public static ClosableContainer createContainer(DockerClient dockerClient, CreateContainerCmd createCmd) {
    CreateContainerResponse commandResponse = createCmd.exec();
    String containerId = commandResponse.getId();
    return new ClosableContainer(dockerClient, containerId);
}
 
开发者ID:retz,项目名称:retz,代码行数:6,代码来源:ClosableContainer.java

示例8: createContainer

import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
/**
	 * creates {@link Container}
	 * 
	 * @param element - {@link Element}
	 * @param host - host ip address
	 * @return id of created {@link Container}
	 * @throws Exception
	 */
	public String createContainer(Element element, String host) throws Exception {
		RestartPolicy restartPolicy = RestartPolicy.onFailureRestart(10);

		Ports portBindings = new Ports();
		List<ExposedPort> exposedPorts = new ArrayList<>();
		if (element.getPortMappings() != null)
			element.getPortMappings().forEach(mapping -> {
				ExposedPort internal = ExposedPort.tcp(Integer.parseInt(mapping.getInside()));
				Ports.Binding external = Ports.Binding(Integer.parseInt(mapping.getOutside()));
				portBindings.bind(internal, external);
				exposedPorts.add(internal);
			});
		String[] extraHosts = { host };
		
		Map<String, String> containerLogConfig = new HashMap<String, String>();
		int logFiles = 1; 
		if (element.getLogSize() > 2)
			logFiles = (int) (element.getLogSize() / 2); 

		containerLogConfig.put("max-file", String.valueOf(logFiles));
		containerLogConfig.put("max-size", "2m");
		LogConfig containerLog = new LogConfig(LogConfig.LoggingType.DEFAULT, containerLogConfig);
		
		CreateContainerCmd cmd = dockerClient.createContainerCmd(element.getImageName())
				.withLogConfig(containerLog)
				.withCpuset("0")
				.withExposedPorts(exposedPorts.toArray(new ExposedPort[0]))
				.withPortBindings(portBindings)
				.withEnv("SELFNAME=" + element.getElementId())
				.withName(element.getElementId())
				.withRestartPolicy(restartPolicy);
//		if (element.getImageName().startsWith("iotracks/catalog:core-networking"))
//			cmd = cmd.withMemoryLimit(256 * Constants.MiB);
		if (StringUtil.isNullOrEmpty(host))
			cmd = cmd.withNetworkMode("host").withPrivileged(true);
		else
			cmd = cmd.withExtraHosts(extraHosts);
		CreateContainerResponse resp = cmd.exec();
		return resp.getId();
	}
 
开发者ID:iotracks,项目名称:iofabric,代码行数:49,代码来源:DockerUtil.java

示例9: createContainer

import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
public void createContainer(String imageId, String containerName, boolean mountFolders,
    String... env) {

  if (!existsContainer(containerName)) {

    pullImageIfNecessary(imageId, false);

    log.debug("Creating container {}", containerName);

    CreateContainerCmd createContainerCmd =
        getClient().createContainerCmd(imageId).withName(containerName).withEnv(env)
        .withVolumes(new Volume("/var/run/docker.sock"));

    if (mountFolders) {
      mountDefaultFolders(createContainerCmd);
    }

    createContainerCmd.exec();

    log.debug("Container {} started...", containerName);

  } else {
    log.debug("Container {} already exists", containerName);
  }
}
 
开发者ID:Kurento,项目名称:kurento-java,代码行数:26,代码来源:Docker.java

示例10: createContainer

import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
@Override
public Container createContainer(Environment env, String containerName, ImageConfiguration imageConf, Image image, String command) throws ContainerizationException {
    CreateContainerResponse containerCreateResponse = null;
    InspectContainerResponse containerInspectResponse = null;
    try {
        CreateContainerCmd createContainerCommand = getDockerClient().createContainerCmd(image.getId());
        createContainerCommand.withName(containerName);
        // keep the container alive
        //containerConfig.setCmd(new String[]{"/bin/bash", "/home/synaptiq/run_tomcat.sh", dockerHost, "" + mysqlPort});
        if (command != null) {
            createContainerCommand.withCmd(command.split(" "));
        }
        List<ExposedPort> exposedPorts = new ArrayList<ExposedPort>();
        if (imageConf.getPorts() != null) {
            for (PortConfiguration port : imageConf.getPorts()) {
                exposedPorts.add(new ExposedPort("tcp", port.getContainerPort()));
            }
        }
        createContainerCommand.withExposedPorts(exposedPorts.toArray(new ExposedPort[0]));
        createContainerCommand.withTty(false);
        List<Volume> volumesList = new ArrayList<Volume>();
        if (imageConf.getVolumes() != null) {
            for (VolumeConfiguration volumeConfiguration : imageConf.getVolumes()) {
                volumesList.add(new Volume(volumeConfiguration.getPath()));
            }
        }
        createContainerCommand.withVolumes(volumesList.toArray(new Volume[0]));

        if (imageConf.getEnvironment() != null) {
            List<String> environmentVariables = new ArrayList<String>();
            for (EnvironmentVariableConfiguration evc : imageConf.getEnvironment()) {
                environmentVariables.add(evc.getVariable() + "=" + evc.getValue());
            }
            createContainerCommand.withEnv(environmentVariables.toArray(new String[0]));
        }

        containerCreateResponse = createContainerCommand.exec();

        containerInspectResponse = getDockerClient().inspectContainerCmd(containerCreateResponse.getId()).exec();

        DockerContainer dockerContainer = new DockerContainer(containerCreateResponse, containerInspectResponse, image);

        return dockerContainer;
    } catch(Exception ex) {
        if (containerCreateResponse != null) {
            try {
                getDockerClient().killContainerCmd(containerCreateResponse.getId()).exec();
                getDockerClient().removeContainerCmd(containerCreateResponse.getId()).exec();
            }
            catch(DockerException e) {
                throw new ContainerizationException(e);
            }
        }
        throw new ContainerizationException(ex);
    }
}
 
开发者ID:ssouporg,项目名称:denv,代码行数:57,代码来源:DockerContainerManager.java


注:本文中的com.github.dockerjava.api.command.CreateContainerCmd.exec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。