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


Java ContainerCreation类代码示例

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


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

示例1: run

import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
public Future<TaskResult> run(Task task) {
    validateTask(task);

    final String functionName = task.getName();
    cleanContainers(functionName);

    final ContainerConfig containerConfig = prepareContainer(task);

    try {
        final ContainerCreation container = dockerClient.createContainer(containerConfig);
        final String containerId = container.id();
        dockerClient.startContainer(containerId);
        final Boolean containerStatus = dockerClient.inspectContainer(containerId).state().running();
        if (!containerStatus) {
            cleanContainers(functionName);
        }
        final TaskId taskId = new TaskId(functionName, containerId);
        return SimpleFuture.success(TaskResult.builder().taskId(taskId).success(containerStatus).build());
    } catch (Exception e) {
        log.error("create container failed: " + e.getMessage(), e);
        cleanContainers(functionName);
        return SimpleFuture.failed(e);
    }
}
 
开发者ID:dshell-io,项目名称:dshell,代码行数:25,代码来源:LocalEngine.java

示例2: create

import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
@Override
public Container create(final String image, final String scripts) {
    try {
        final ContainerCreation container = this.client.createContainer(
            ContainerConfig
                .builder()
                .image(image)
                .cmd("/bin/bash", "-c", scripts)
                .build()
        );
        return new Docker(container.id(), this);
    } catch (final DockerException | InterruptedException ex) {
        throw new IllegalStateException(
            "Exception when creating the container "
            + "with image: " + image + " and scripts: " + scripts, ex
        );
    }
}
 
开发者ID:amihaiemil,项目名称:comdor,代码行数:19,代码来源:RtDockerHost.java

示例3: startInstance

import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
@Override
public ContainerCloudInstance startInstance(@NotNull String instanceId, @NotNull ContainerCloudImage image, @NotNull CloudInstanceUserData tag) {
    try {
        LOG.debug("Pulling image " + image.getId());
        dockerClient.pull(image.getId());

        List<String> environment = new ArrayList<>();
        tag.getCustomAgentConfigurationParameters().forEach((key, value) -> environment.add(key + "=" + value));

        ContainerConfig cfg = ContainerConfig.builder()
                .image(image.getId())
                .env(environment)
                .build();
        ContainerCreation creation = dockerClient.createContainer(cfg, instanceId);
        LOG.debug("Starting image " + image.getId());
        dockerClient.startContainer(creation.id());

        return new ContainerCloudInstance(instanceId, image, this);
    } catch (Exception e) {
        throw new CloudException("Failed to start instance of image " + image.getId(), e);
    }
}
 
开发者ID:carlpett,项目名称:teamcity-container-cloud,代码行数:23,代码来源:DockerSocketContainerProvider.java

示例4: runContainer

import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
public String runContainer(ContainerConfig.Builder containerConfigBuilder, String containerName) throws DockerException {
    try {
        final ContainerConfig containerConfig = containerConfigBuilder.build();
        final ContainerCreation creation;

        creation = dockerClient.createContainer(containerConfig, containerName);

        final String id = creation.id();
        dockerClient.startContainer(id);
        return id;
    } catch (InterruptedException e) {
        logger.error("", e);
    }

    return null;
}
 
开发者ID:simpleci,项目名称:simpleci,代码行数:17,代码来源:DockerContainerManager.java

示例5: create

import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
public static DockerContainer create(CreateAgentRequest request, PluginSettings settings, DockerClient docker) throws InterruptedException, DockerException, IOException {
    String containerName = UUID.randomUUID().toString();

    HashMap<String, String> labels = labelsFrom(request);
    String imageName = image(request.properties());
    List<String> env = environmentFrom(request, settings, containerName);

    try {
        docker.inspectImage(imageName);
    } catch (ImageNotFoundException ex) {
        LOG.info("Image " + imageName + " not found, attempting to download.");
        docker.pull(imageName);
    }

    ContainerConfig.Builder containerConfigBuilder = ContainerConfig.builder();
    if (StringUtils.isNotBlank(request.properties().get("Command"))) {
        containerConfigBuilder.cmd(splitIntoLinesAndTrimSpaces(request.properties().get("Command")).toArray(new String[]{}));
    }

    final String hostConfig = request.properties().get("Hosts");

    ContainerConfig containerConfig = containerConfigBuilder
            .image(imageName)
            .labels(labels)
            .env(env)
            .hostConfig(HostConfig.builder().extraHosts(new Hosts(hostConfig)).build())
            .build();

    ContainerCreation container = docker.createContainer(containerConfig, containerName);
    String id = container.id();

    ContainerInfo containerInfo = docker.inspectContainer(id);

    LOG.debug("Created container " + containerName);
    docker.startContainer(containerName);
    LOG.debug("container " + containerName + " started");
    return new DockerContainer(containerName, containerInfo.created(), request.properties(), request.environment());
}
 
开发者ID:gocd-contrib,项目名称:docker-elastic-agents,代码行数:39,代码来源:DockerContainer.java

示例6: start

import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
@Override
public void start(WorkflowInstance workflowInstance, RunSpec runSpec) {
  final String imageTag = runSpec.imageName().contains(":")
      ? runSpec.imageName()
      : runSpec.imageName() + ":latest";

  final ContainerCreation creation;
  try {
    boolean found = false;
    for (Image image : client.listImages()) {
      found |= image.repoTags().contains(imageTag);
    }

    if (!found) {
      client.pull(imageTag, System.out::println); // blocking
    }

    final ContainerConfig containerConfig = ContainerConfig.builder()
        .image(imageTag)
        .cmd(runSpec.args())
        .build();
    creation = client.createContainer(containerConfig, runSpec.executionId());
    client.startContainer(creation.id());
  } catch (DockerException | InterruptedException e) {
    throw new RuntimeException(e);
  }

  inFlight.put(creation.id(), workflowInstance);
  LOG.info("Started container with id " + creation.id() + " and name " + runSpec.executionId());
}
 
开发者ID:spotify,项目名称:styx,代码行数:31,代码来源:LocalDockerRunner.java

示例7: testCreateContainer

import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
@Test
public void testCreateContainer() throws Exception, MccyException {
    ContainerRequest request = new ContainerRequest();
    request.setName("server-1");
    request.setStartOnCreate(true);
    request.setAckEula(true);

    when(dockerClient.createContainer(any(ContainerConfig.class), anyString()))
            .thenReturn(new ContainerCreation("id-1"));

    ContainerConfig stubbedConfig = ContainerConfig.builder().build();
    when(containerBuilderService.buildContainerConfig(any(), any(), any()))
            .thenReturn(stubbedConfig);

    final UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString("http://localhost:8080");
    containersService.setProxyUriBuilder(uriComponentsBuilder);

    final String id = containersService.create(request, "user1",
            containerCreateStatus -> {});

    verify(dockerClient).pull(anyString(), any(ProgressHandler.class));

    final ArgumentCaptor<ContainerConfig> containerConfigCaptor =
            ArgumentCaptor.forClass(ContainerConfig.class);
    verify(dockerClient).createContainer(containerConfigCaptor.capture(), eq("server_1"));

    verify(dockerClient).startContainer(eq(id));

    Mockito.verifyNoMoreInteractions(dockerClient);

    assertThat(id, not(isEmptyOrNullString()));
    assertEquals(id, "id-1");
}
 
开发者ID:moorkop,项目名称:mccy-engine,代码行数:34,代码来源:ContainersServiceTest.java

示例8: startContainer

import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
private void startContainer() throws Exception {
    final DockerClient dockerClient = DefaultDockerClient.fromEnv().build();
    logger.info("Pulling image spotify/kafka");
    dockerClient.pull("spotify/kafka");
    final String[] ports = {"2181", "9092"};
    List<String> env = new ArrayList<>();
    env.add("ADVERTISED_PORT=9092");
    env.add("ADVERTISED_HOST=192.168.59.103");

    final Map<String, List<PortBinding>> portBindings = new HashMap<>();
    for (String port : ports) {
        List<PortBinding> hostPorts = new ArrayList<>();
        hostPorts.add(PortBinding.of("0.0.0.0", port));
        portBindings.put(port, hostPorts);
    }
    final HostConfig hostConfig = HostConfig.builder().portBindings(portBindings).build();

    final ContainerConfig containerConfig = ContainerConfig.builder()
            .hostConfig(hostConfig)
            .image("spotify/kafka")
            .exposedPorts(ports)
            .env(env)
            .build();

    final ContainerCreation creation = dockerClient.createContainer(containerConfig);
    containerId = creation.id();
    logger.info("Starting container");

    // Start container
    dockerClient.startContainer(containerId);
}
 
开发者ID:SaschaMoellering,项目名称:ingestion-service,代码行数:32,代码来源:KafkaKinesisIntegrationTest.java

示例9: execute

import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
/**
 * Executes a containerized command on AWS.
 */
public String execute(String dockerImage, List<String> envList, List<String> commandList, String entryPoint) throws CommandExecutionException {
    try( DockerClient dockerClient = new DefaultDockerClient("unix:///var/run/docker.sock")) {
        String response = null;
        //pullImage(dockerClient, dockerImage);
        dockerClient.pull(dockerImage);

        if (commandList != null && !commandList.isEmpty()) {
            if (commandList.get(0).equalsIgnoreCase(entryPoint)) {
                commandList = commandList.subList(1, commandList.size());
            }
        }

        final ContainerConfig containerConfig = ContainerConfig.builder()
                .image(dockerImage)
                .env(envList)
                .entrypoint(entryPoint)
                .cmd(commandList)
                .build();

        final ContainerCreation container = dockerClient.createContainer(containerConfig);
        final String containerId = container.id();
        dockerClient.startContainer(containerId);

        // Wait for the container to exit.
        // If we don't wait, docker.logs() might return an epmty string because the container
        // cmd hasn't run yet.
        dockerClient.waitContainer(containerId);

        final String log;
        try (LogStream logs = dockerClient.logs(containerId, stdout(), stderr())) {
            log = logs.readFully();
        }
        logger.info(log);
        response = log;
        dockerClient.removeContainer(containerId);

        return response;
    } catch (DockerException | InterruptedException e) {
        throw new CommandExecutionException(e);
    }
}
 
开发者ID:sjsucohort6,项目名称:amigo-chatbot,代码行数:45,代码来源:DockerTask.java

示例10: commitContainer

import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
@Override
public ContainerCreation commitContainer(String string, String string1, String string2, ContainerConfig cc, String string3, String string4) {
    throw new IllegalStateException(DISCONNECTED); 
}
 
开发者ID:amihaiemil,项目名称:comdor,代码行数:5,代码来源:Disconnected.java

示例11: createContainer

import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
@Override
public ContainerCreation createContainer(ContainerConfig cc) {
    throw new IllegalStateException(DISCONNECTED); 
}
 
开发者ID:amihaiemil,项目名称:comdor,代码行数:5,代码来源:Disconnected.java


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