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


Java ContainerCreation.id方法代码示例

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


在下文中一共展示了ContainerCreation.id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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

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

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


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