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


Java CreateContainerCmd类代码示例

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


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

示例1: build

import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, Volume v) {
	Bind[] binds = cmd.getBinds();
	
	String hostPath = v.useClasspath() 
			? Thread.currentThread().getContextClassLoader()
					.getResource(v.host()).getPath()
			: v.host();
	
	Bind bind = new Bind(hostPath, 
			new com.github.dockerjava.api.model.Volume(v.container()), 
			AccessMode.fromBoolean(v.accessMode().equals(Volume.AccessMode.RW)));
	
	List<Bind> bindsList = new ArrayList<>();
	if(binds != null) {
		bindsList.addAll(Arrays.asList(binds));
	} 
	bindsList.add(bind);  	
    return cmd.withBinds(bindsList);
}
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:21,代码来源:VolumeExtensionInterpreter.java

示例2: 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

示例3: build

import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, WebHealthCheck whc) {
	final String serviceNameEnv = SERVICE_PREFIX + whc.exposedPort() + SERVICE_NAME_SUFFIX + "=" + td.getNamed().value();
	final String serviceCheckScriptEnv = SERVICE_CHECK_SCRIPT + "=`which curl` -f " 
			+ (whc.protocol().equals(WebProtocol.HTTPS) ? "-sSk " : "")
			+ whc.protocol().toString().toLowerCase()
			+ "://$SERVICE_IP:$SERVICE_PORT"
			+ whc.endpoint();
	final String serviceCheckIntervalEnv = SERVICE_CHECK_INTERVAL + "=" + whc.pollingInterval() + "s";
	
	List<String> finalEnv = new ArrayList<>();
	List<String> healthCheckEnv = Arrays.asList(serviceNameEnv, serviceCheckScriptEnv, serviceCheckIntervalEnv);
	finalEnv.addAll(healthCheckEnv);

	String[] env = cmd.getEnv();
	
	if(env != null) {
		finalEnv.addAll(Arrays.asList(env));
	}
	return cmd.withEnv(finalEnv);
}
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:22,代码来源:WebHealthCheckExtensionInterpreter.java

示例4: dockerCommand

import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
protected CreateContainerCmd dockerCommand() {
    int port = getServicePort();
    ExposedPort exposedPort = ExposedPort.tcp(port);

    Ports portBindings = new Ports();
    if (getCluster().isMapPortsToHost()) {
        portBindings.bind(exposedPort, Ports.Binding.bindPort(port));
    }

    CreateContainerCmd cmd = DockerClientFactory.build().createContainerCmd(getImageName() + ":" + getImageTag())
        .withName(getName())
        .withExposedPorts(new ExposedPort(getServicePort()))
        .withEnv(newEnvironment()
            .withValues(getMesosMasterEnvVars())
            .withValues(getSharedEnvVars())
            .createEnvironment())
        .withPortBindings(portBindings);

    MesosDns mesosDns = getCluster().getMesosDns();
    if (mesosDns != null) {
        cmd.withDns(mesosDns.getIpAddress());
    }

    return cmd;
}
 
开发者ID:ContainerSolutions,项目名称:minimesos,代码行数:27,代码来源:MesosMasterContainer.java

示例5: dockerCommand

import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
protected CreateContainerCmd dockerCommand() {
    int port = getServicePort();
    ExposedPort exposedPort = ExposedPort.tcp(port);

    Ports portBindings = new Ports();
    if (getCluster().isMapPortsToHost()) {
        portBindings.bind(exposedPort, Ports.Binding.bindPort(port));
    }

    ExposedPort consulHTTPPort = ExposedPort.tcp(ConsulConfig.CONSUL_HTTP_PORT);
    ExposedPort consulDNSPort = ExposedPort.udp(ConsulConfig.CONSUL_DNS_PORT);

    return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag())
            .withName(getName())
            .withCmd("agent", "-server", "-bootstrap", "-client", "0.0.0.0")
            .withExposedPorts(consulHTTPPort, consulDNSPort)
            .withPortBindings(portBindings);
}
 
开发者ID:ContainerSolutions,项目名称:minimesos,代码行数:20,代码来源:ConsulContainer.java

示例6: runInsideDocker

import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
private <T> T runInsideDocker(DockerClient client, Consumer<CreateContainerCmd> createContainerCmdConsumer, BiFunction<DockerClient, String, T> block) {
    checkAndPullImage(client, TINY_IMAGE);
    CreateContainerCmd createContainerCmd = client.createContainerCmd(TINY_IMAGE);
    createContainerCmdConsumer.accept(createContainerCmd);
    String id = createContainerCmd.exec().getId();

    try {
        client.startContainerCmd(id).exec();
        return block.apply(client, id);
    } finally {
        try {
            client.removeContainerCmd(id).withRemoveVolumes(true).withForce(true).exec();
        } catch (NotFoundException | InternalServerErrorException ignored) {
            log.debug("", ignored);
        }
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:18,代码来源:DockerClientFactory.java

示例7: 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

示例8: testPortBinding

import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Test
public void testPortBinding() throws IOException, InterruptedException {
    DockerComputerSSHConnector connector = new DockerComputerSSHConnector(Mockito.mock(DockerComputerSSHConnector.SSHKeyStrategy.class));
    CreateContainerCmdImpl cmd = new CreateContainerCmdImpl(Mockito.mock(CreateContainerCmd.Exec.class), "");
    cmd.withPortBindings(PortBinding.parse("42:42"));

    connector.setPort(22);
    connector.beforeContainerCreated(Mockito.mock(DockerAPI.class), "/workdir", cmd);
    final Ports portBindings = cmd.getPortBindings();
    Assert.assertNotNull(portBindings);
    final Map<ExposedPort, Ports.Binding[]> bindingMap = portBindings.getBindings();
    Assert.assertNotNull(bindingMap);
    Assert.assertEquals(2, bindingMap.size());

    final Ports.Binding[] configuredBindings = bindingMap.get(new ExposedPort(42));
    Assert.assertNotNull(configuredBindings);
    Assert.assertEquals(1, configuredBindings.length);
    Assert.assertEquals("42", configuredBindings[0].getHostPortSpec());

    final Ports.Binding[] sshBindings = bindingMap.get(new ExposedPort(22));
    Assert.assertNotNull(sshBindings);
    Assert.assertEquals(1, sshBindings.length);
    Assert.assertNull(sshBindings[0].getHostPortSpec());

    System.out.println();
}
 
开发者ID:jenkinsci,项目名称:docker-plugin,代码行数:27,代码来源:DockerComputerSSHConnectorTest.java

示例9: resolveExposedPorts

import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
private Set<ExposedPort> resolveExposedPorts(CubeContainer containerConfiguration,
    CreateContainerCmd createContainerCmd) {
    Set<ExposedPort> allExposedPorts = new HashSet<>();
    if (containerConfiguration.getPortBindings() != null) {
        for (PortBinding binding : containerConfiguration.getPortBindings()) {
            allExposedPorts.add(new ExposedPort(binding.getExposedPort().getExposed(),
                InternetProtocol.parse(binding.getExposedPort().getType())));
        }
    }
    if (containerConfiguration.getExposedPorts() != null) {
        for (org.arquillian.cube.docker.impl.client.config.ExposedPort port : containerConfiguration.getExposedPorts()) {
            allExposedPorts.add(new ExposedPort(port.getExposed(), InternetProtocol.parse(port.getType())));
        }
    }
    return allExposedPorts;
}
 
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:17,代码来源:DockerClientExecutor.java

示例10: 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

示例11: build

import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, PortBindings pbs) {
    for (PortBinding pb : pbs.value()) {
        cmd = builder.build(td, cmd, pb);
    }
    return cmd;
}
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:8,代码来源:PortBindingWrapperExtensionInterpreter.java

示例12: build

import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, Env t) {
	String[] env = cmd.getEnv();
	List<String> finalEnv = new ArrayList<>();
	finalEnv.addAll(Arrays.asList(t.value()));
	if (env != null) {
		finalEnv.addAll(Arrays.asList(env));
	}
	return cmd.withEnv(finalEnv);
}
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:11,代码来源:EnvExtensionInterpreter.java

示例13: build

import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, Volumes vs) {
    for (Volume v : vs.value()) {
        cmd = builder.build(td, cmd, v);
    }
    return cmd;
}
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:8,代码来源:VolumeWrapperExtensionInterpreter.java

示例14: createInstance

import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
private ServiceInstance createInstance(TestDescriptor descriptor, DockerClient client, int i) {
      CreateContainerCmd cmd = client.createContainerCmd(descriptor.getImage().value());
      cmd = computeContainerName(descriptor, i, cmd);
      cmd = executeOptionBuilders(descriptor, cmd);
      if (descriptor.getCustomisationHook() != null) {
          cmd = executeCustomisationHook(descriptor.getCustomisationHook(), descriptor.getInstance(), cmd);
      }
      String containerId = null;
      Status status = null;
      String statusDetails = null;
try {
	containerId = createAndStartContainer(cmd, descriptor.getImage().pull(),  client);
	status = Status.STARTED;
	statusDetails = "Started.";
} catch (Throwable t) {
	if(t instanceof CompletionException) {
		if(t.getCause() != null && t.getCause() instanceof ContainerException) {
			containerId = ((ContainerException) t.getCause()).getContainerId();
			statusDetails = t.getCause().getCause() != null ? t.getCause().getCause().getMessage() : null;
		} else {
			statusDetails = t.getCause() != null ? t.getCause().getMessage() : null;
		}	
	} else {
		statusDetails = t.getMessage();
	}
	status = Status.ABORTED;
}
return ServiceInstance.builder()
              .containerName(cmd.getName())
              .containerId(containerId)
              .status(status)
              .statusDetails(statusDetails)
              .build();
  }
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:35,代码来源:DefaultServiceBuilder.java

示例15: computeContainerName

import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
private CreateContainerCmd computeContainerName(TestDescriptor dependency, int i, CreateContainerCmd cmd) {
	if (!dependency.getContainerName()
           .isEmpty()) {
           String name = dependency.getReplicas() > 1 
           		? dependency.getContainerName() +  "-" + (i + 1)  
           		: dependency.getContainerName();
           cmd = cmd.withName(name);
       }
	return cmd;
}
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:11,代码来源:DefaultServiceBuilder.java


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