• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DockerException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createNetwork

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
/**
 * Create network which is used as default in docker-compose.yml
 * This should be run before {@link DockerComposeExecutor#run(TestEnvironment)}
 */
@Override
public void createNetwork() {
    removeNetwork();

    String apmNetwork = apmBindAddress.substring(0, apmBindAddress.lastIndexOf(".")) + ".0/24";

    log.info(String.format("Creating network %s:", apmNetwork));

    Network.Ipam ipam = new Network.Ipam()
            .withConfig(new Network.Ipam.Config()
                    .withSubnet(apmNetwork)
                    .withGateway(apmBindAddress));

    CreateNetworkResponse createNetworkResponse = dockerClient.createNetworkCmd()
            .withName(Constants.HOST_ADDED_TO_ETC_HOSTS)
            .withIpam(ipam)
            .exec();

    try {
        network = dockerClient.inspectNetworkCmd().withNetworkId(createNetworkResponse.getId()).exec();
    } catch (DockerException ex) {
        log.severe(String.format("Could not create network: %s", createNetworkResponse));
        throw new EnvironmentException("Could not create network: " + createNetworkResponse, ex);
    }
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:30,代码来源:AbstractDockerBasedEnvironment.java


示例2: registerContainersForShutdown

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
private void registerContainersForShutdown() {
    // Ensure that all service containers that were launched by compose will be killed at shutdown
    try {
        final List<Container> containers = listChildContainers();

        // register with ResourceReaper to ensure final shutdown with JVM
        containers.forEach(container ->
                ResourceReaper.instance().registerContainerForCleanup(container.getId(), container.getNames()[0]));

        // Compose can define their own networks as well; ensure these are cleaned up
        dockerClient.listNetworksCmd().exec().forEach(network -> {
            if (network.getName().contains(identifier)) {
                spawnedNetworkIds.add(network.getId());
                ResourceReaper.instance().registerNetworkIdForCleanup(network.getId());
            }
        });

        // remember the IDs to allow containers to be killed as soon as we reach stop()
        spawnedContainerIds.addAll(containers.stream()
                .map(Container::getId)
                .collect(Collectors.toSet()));

    } catch (DockerException e) {
        logger().debug("Failed to stop a service container with exception", e);
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:27,代码来源:DockerComposeContainer.java


示例3: perform

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Override
public boolean perform(@SuppressWarnings("rawtypes") AbstractBuild build, Launcher launcher, BuildListener listener)
        throws AbortException {

    ConsoleLogger clog = new ConsoleLogger(listener);

    if (getDescriptor().getDockerClient(build, null) == null) {
        clog.logError("docker client is not initialized, command '" + dockerCmd.getDescriptor().getDisplayName()
                + "' was aborted. Check Jenkins server log which Docker client wasn't initialized");
        throw new AbortException("Docker client wasn't initialized.");
    }

    try {
        dockerCmd.execute(launcher, build, clog);
    } catch (DockerException e) {
        clog.logError("command '" + dockerCmd.getDescriptor().getDisplayName() + "' failed: " + e.getMessage());
        LOGGER.severe("Failed to execute Docker command " + dockerCmd.getDescriptor().getDisplayName() + ": "
                + e.getMessage());
        throw new AbortException(e.getMessage());
    } 
    return true;
}
 
开发者ID:jenkinsci,项目名称:docker-build-step-plugin,代码行数:23,代码来源:DockerBuilder.java


示例4: logCommandResult

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
public static void logCommandResult(InputStream inputStream,
        ConsoleLogger console, String errMessage) {
    BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
    String line = null;
    try {
      while((line = in.readLine()) != null) {
        console.logInfo(line);
        JSONObject jsonResponse = JSONObject.fromObject(line);
        if (jsonResponse.containsKey("error") || jsonResponse.containsKey("errorDetail")) {
          throw new DockerException(line, 200);
        }
      }
    } catch (IOException e) {
      throw new DockerException(line == null ? errMessage : line, 200, e);
    }
}
 
开发者ID:jenkinsci,项目名称:docker-build-step-plugin,代码行数:17,代码来源:CommandUtils.java


示例5: execute

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Override
public void execute(Launcher launcher, @SuppressWarnings("rawtypes") AbstractBuild build, ConsoleLogger console)
        throws DockerException {
    if (containerIds == null || containerIds.isEmpty()) {
        throw new IllegalArgumentException("At least one parameter is required");
    }

    String containerIdsRes = Resolver.buildVar(build, containerIds);
    List<String> ids = Arrays.asList(containerIdsRes.split(","));
    
    Config cfgData = getConfig(build);
    Descriptor<?> descriptor = Jenkins.getInstance().getDescriptor(DockerBuilder.class);
    for (String id : ids) {
        id = id.trim();
        
        try {
            launcher.getChannel().call(new KillContainerRemoteCallable(cfgData, descriptor, id));
        	console.logInfo("killed container id " + id);
        } catch (Exception e) {
            console.logError("failed to kill containers " + ids);
            e.printStackTrace();
            throw new IllegalArgumentException(e);
        }
    }
}
 
开发者ID:jenkinsci,项目名称:docker-build-step-plugin,代码行数:26,代码来源:KillCommand.java


示例6: execute

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Override
public void execute(Launcher launcher, @SuppressWarnings("rawtypes") AbstractBuild build, ConsoleLogger console) throws DockerException {
    if (containerIds == null || containerIds.isEmpty()) {
        throw new IllegalArgumentException("At least one parameter is required");
    }
    
    String containerIdsRes = Resolver.buildVar(build, containerIds);
    List<String> ids = Arrays.asList(containerIdsRes.split(","));
    
    try {
        Config cfgData = getConfig(build);
        Descriptor<?> descriptor = Jenkins.getInstance().getDescriptor(DockerBuilder.class);
        
        for (String id : ids) {
            id = id.trim();
            launcher.getChannel().call(new RestartContainerRemoteCallable(cfgData, descriptor, id, timeout));
            console.logInfo("restarted container id " + id);
        }
    } catch (Exception e) {
        console.logError("failed to restart containers ids " + ids);
        e.printStackTrace();
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:jenkinsci,项目名称:docker-build-step-plugin,代码行数:25,代码来源:RestartCommand.java


示例7: execute

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Override
public void execute(Launcher launcher, @SuppressWarnings("rawtypes") AbstractBuild build, ConsoleLogger console)
        throws DockerException {
    
    
    try {
        Config cfgData = getConfig(build);
        Descriptor<?> descriptor = Jenkins.getInstance().getDescriptor(DockerBuilder.class);
        
        List<Container> containers = launcher.getChannel().call(new ListContainersRemoteCallable(cfgData, descriptor, false));
        
        for (Container container : containers) {
            launcher.getChannel().call(new RemoveContainerRemoteCallable(cfgData, descriptor, container.getId(), force, removeVolumes));
            console.logInfo("removed container id " + container.getId());
        }
    } catch (Exception e) {
        console.logError("failed to stop all containers");
        e.printStackTrace();
        throw new IllegalArgumentException(e);
    }
    
}
 
开发者ID:jenkinsci,项目名称:docker-build-step-plugin,代码行数:23,代码来源:RemoveAllCommand.java


示例8: execute

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Override
public void execute(Run<?, ?> build, Launcher launcher, TaskListener listener)
        throws DockerException {
    final PrintStream llog = listener.getLogger();

    LOG.info("Stopping all containers");
    llog.println("Stopping all containers");

    for (DockerLaunchAction.Item containerItem : getLaunchAction(build).getRunning()) {
        LOG.info("Stopping container {}", containerItem.id);
        llog.println("Stopping container " + containerItem.id);

        containerItem.client.stopContainerCmd(containerItem.id).exec();

        if (remove) {
            LOG.info("Removing container {}", containerItem.id);
            llog.println("Removing container " + containerItem.id);

            containerItem.client.removeContainerCmd(containerItem.id).exec();
        }
    }
}
 
开发者ID:jenkinsci,项目名称:docker-plugin,代码行数:23,代码来源:DockerBuilderControlOptionStopAll.java


示例9: inspectContainerWithSize

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test()
public void inspectContainerWithSize() throws DockerException {

    String containerName = "generated_" + new SecureRandom().nextInt();

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("top")
            .withName(containerName).exec();
    LOG.info("Created container {}", container.toString());
    assertThat(container.getId(), not(isEmptyString()));

    InspectContainerCmd command = dockerRule.getClient().inspectContainerCmd(container.getId()).withSize(true);
    assertTrue(command.getSize());
    InspectContainerResponse containerInfo = command.exec();
    assertEquals(containerInfo.getId(), container.getId());

    // TODO check swarm
    if (isNotSwarm(dockerRule.getClient())) {
        assertNotNull(containerInfo.getSizeRootFs());
        assertTrue(containerInfo.getSizeRootFs().intValue() > 0);
    }
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:22,代码来源:InspectContainerCmdIT.java


示例10: killContainer

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test
public void killContainer() throws DockerException {

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999").exec();
    LOG.info("Created container: {}", container.toString());
    assertThat(container.getId(), not(isEmptyString()));
    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    LOG.info("Killing container: {}", container.getId());
    dockerRule.getClient().killContainerCmd(container.getId()).exec();

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();
    LOG.info("Container Inspect: {}", inspectContainerResponse.toString());

    assertThat(inspectContainerResponse.getState().getRunning(), is(equalTo(false)));
    assertThat(inspectContainerResponse.getState().getExitCode(), not(equalTo(0)));

}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:19,代码来源:KillContainerCmdIT.java


示例11: removeVolume

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test(expected = NotFoundException.class)
public void removeVolume() throws DockerException {

    String volumeName = "volume1" + dockerRule.getKind();

    CreateVolumeResponse createVolumeResponse = dockerRule.getClient().createVolumeCmd()
            .withName(volumeName)
            .withDriver("local").exec();

    assertThat(createVolumeResponse.getName(), equalTo(volumeName));
    assertThat(createVolumeResponse.getDriver(), equalTo("local"));
    assertThat(createVolumeResponse.getMountpoint(), containsString(volumeName));

    dockerRule.getClient().removeVolumeCmd(volumeName).exec();

    dockerRule.getClient().inspectVolumeCmd(volumeName).exec();
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:18,代码来源:RemoveVolumeCmdIT.java


示例12: inspectNetwork

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test
public void inspectNetwork() throws DockerException {
    assumeNotSwarm("no network in swarm", dockerRule);

    List<Network> networks = dockerRule.getClient().listNetworksCmd().exec();

    Network expected = findNetwork(networks, "bridge");

    Network network = dockerRule.getClient().inspectNetworkCmd().withNetworkId(expected.getId()).exec();

    assertThat(network.getName(), equalTo(expected.getName()));
    assertThat(network.getScope(), equalTo(expected.getScope()));
    assertThat(network.getDriver(), equalTo(expected.getDriver()));
    assertThat(network.getIpam().getConfig().get(0).getSubnet(), equalTo(expected.getIpam().getConfig().get(0).getSubnet()));
    assertThat(network.getIpam().getDriver(), equalTo(expected.getIpam().getDriver()));
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:17,代码来源:InspectNetworkCmdIT.java


示例13: createContainerWithShmPidsLimit

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@SuppressWarnings("Duplicates")
@Test
public void createContainerWithShmPidsLimit() throws DockerException {
    assumeThat("API version should be >= 1.23", dockerRule, isGreaterOrEqual(VERSION_1_23));

    HostConfig hostConfig = new HostConfig().withPidsLimit(2L);
    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withHostConfig(hostConfig).withCmd("true").exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(isEmptyString()));

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    assertThat(inspectContainerResponse.getHostConfig().getPidsLimit(), is(hostConfig.getPidsLimit()));
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:18,代码来源:CreateContainerCmdIT.java


示例14: createVolumeWithExistingName

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test
public void createVolumeWithExistingName() throws DockerException {

    String volumeName = "volume1";

    CreateVolumeResponse createVolumeResponse1 = dockerRule.getClient().createVolumeCmd().withName(volumeName)
            .withDriver("local").exec();

    assertThat(createVolumeResponse1.getName(), equalTo(volumeName));
    assertThat(createVolumeResponse1.getDriver(), equalTo("local"));
    assertThat(createVolumeResponse1.getMountpoint(), containsString("/volume1/"));

    CreateVolumeResponse createVolumeResponse2 = dockerRule.getClient().createVolumeCmd().withName(volumeName)
            .withDriver("local").exec();

    assertThat(createVolumeResponse2.getName(), equalTo(volumeName));
    assertThat(createVolumeResponse2.getDriver(), equalTo("local"));
    assertThat(createVolumeResponse2.getMountpoint(), equalTo(createVolumeResponse1.getMountpoint()));
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:20,代码来源:CreateVolumeCmdIT.java


示例15: testCreateService

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test
public void testCreateService() throws DockerException {
    dockerRule.getClient().initializeSwarmCmd(new SwarmSpec())
            .withListenAddr("127.0.0.1")
            .withAdvertiseAddr("127.0.0.1")
            .exec();

    dockerRule.getClient().createServiceCmd(new ServiceSpec()
            .withName(SERVICE_NAME)
            .withTaskTemplate(new TaskSpec()
                    .withContainerSpec(new ContainerSpec()
                            .withImage(DEFAULT_IMAGE))))
    .exec();

    List<Service> services = dockerRule.getClient().listServicesCmd()
            .withNameFilter(Lists.newArrayList(SERVICE_NAME))
            .exec();

    assertThat(services, hasSize(1));

    dockerRule.getClient().removeServiceCmd(SERVICE_NAME).exec();
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:23,代码来源:CreateServiceCmdExecIT.java


示例16: initializingSwarmThrowsWhenAlreadyInSwarm

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test(expected = NotAcceptableException.class)
public void initializingSwarmThrowsWhenAlreadyInSwarm() throws DockerException {
    SwarmSpec swarmSpec = new SwarmSpec()
            .withName("swarm");

    dockerRule.getClient().initializeSwarmCmd(swarmSpec)
            .withListenAddr("127.0.0.1")
            .withAdvertiseAddr("127.0.0.1")
            .exec();
    LOG.info("Initialized swarm: {}", swarmSpec.toString());

    // Initializing a swarm if already in swarm mode should fail
    dockerRule.getClient().initializeSwarmCmd(swarmSpec)
            .withListenAddr("127.0.0.1")
            .exec();
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:17,代码来源:InitializeSwarmCmdExecIT.java


示例17: removeImage

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test
public void removeImage() throws DockerException, InterruptedException {

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999").exec();
    LOG.info("Created container: {}", container.toString());
    assertThat(container.getId(), not(isEmptyString()));
    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    LOG.info("Committing container {}", container.toString());
    String imageId = dockerRule.getClient().commitCmd(container.getId()).exec();

    dockerRule.getClient().stopContainerCmd(container.getId()).exec();
    dockerRule.getClient().removeContainerCmd(container.getId()).exec();

    LOG.info("Removing image: {}", imageId);
    dockerRule.getClient().removeImageCmd(imageId).exec();

    List<Container> containers = dockerRule.getClient().listContainersCmd().withShowAll(true).exec();

    Matcher matcher = not(hasItem(hasField("id", startsWith(imageId))));
    assertThat(containers, matcher);
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:23,代码来源:RemoveImageCmdIT.java


示例18: removeNetwork

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test
public void removeNetwork() throws DockerException {
    assumeNotSwarm("Swarm has no network", dockerRule);

    CreateNetworkResponse network = dockerRule.getClient().createNetworkCmd()
            .withName("test-network")
            .exec();

    LOG.info("Removing network: {}", network.getId());
    dockerRule.getClient().removeNetworkCmd(network.getId()).exec();

    List<Network> networks = dockerRule.getClient().listNetworksCmd().exec();

    Matcher matcher = not(hasItem(hasField("id", startsWith(network.getId()))));
    assertThat(networks, matcher);

}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:18,代码来源:RemoveNetworkCmdIT.java


示例19: renameContainer

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test
public void renameContainer() throws DockerException {

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999").exec();
    LOG.info("Created container: {}", container.toString());
    assertThat(container.getId(), not(isEmptyString()));
    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();
    LOG.info("Container Inspect: {}", inspectContainerResponse.toString());

    String name1 = inspectContainerResponse.getName();

    dockerRule.getClient().renameContainerCmd(container.getId())
            .withName(dockerRule.getKind() + "renameContainer")
            .exec();

    InspectContainerResponse inspectContainerResponse2 = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();
    LOG.info("Container Inspect After Rename: {}", inspectContainerResponse2.toString());

    String name2 = inspectContainerResponse2.getName();

    assertNotEquals(name1, name2);

    dockerRule.getClient().killContainerCmd(container.getId()).exec();
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:27,代码来源:RenameContainerCmdIT.java


示例20: createContainerWithName

import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test(expected = ConflictException.class)
public void createContainerWithName() throws DockerException {
    String containerName = "container_" + dockerRule.getKind();

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withName(containerName)
            .withCmd("env").exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(isEmptyString()));

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    assertThat(inspectContainerResponse.getName(), equalTo("/" + containerName));

    dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withName(containerName)
            .withCmd("env")
            .exec();
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:22,代码来源:CreateContainerCmdIT.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Note类代码示例发布时间:2022-05-22
下一篇:
Java PackageImport类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap