當前位置: 首頁>>代碼示例>>Java>>正文


Java DockerClient.inspectContainer方法代碼示例

本文整理匯總了Java中com.spotify.docker.client.DockerClient.inspectContainer方法的典型用法代碼示例。如果您正苦於以下問題:Java DockerClient.inspectContainer方法的具體用法?Java DockerClient.inspectContainer怎麽用?Java DockerClient.inspectContainer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.spotify.docker.client.DockerClient的用法示例。


在下文中一共展示了DockerClient.inspectContainer方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: create

import com.spotify.docker.client.DockerClient; //導入方法依賴的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

示例2: removeContainers

import com.spotify.docker.client.DockerClient; //導入方法依賴的package包/類
private void removeContainers(DockerClient dockerClient, String imageName) throws DockerException, InterruptedException {
    log.debug("about to cleanup all containers created from image {}", imageName);
    List<Container> containers = dockerClient.listContainers(ListContainersParam.allContainers());
    for (Container container : containers) {
        if (imageName.equals(container.image())) {
            ContainerInfo containerInfo = dockerClient.inspectContainer(container.id());
            if (containerInfo.state().running()) {
                throw new IllegalStateException(String.format("container '%s' based on image '%s' is running, this test requires removing all containers created from image '%s'"));
            } else {
                log.debug("removing container {}", container.id());
                dockerClient.removeContainer(container.id());
            }
        }
    }
}
 
開發者ID:tdomzal,項目名稱:junit-docker-rule,代碼行數:16,代碼來源:DockerRuleImagePullTest.java

示例3: inspectContainer

import com.spotify.docker.client.DockerClient; //導入方法依賴的package包/類
public static ContainerInfo inspectContainer(String containerId){
	DockerClient client = getDockerClient();
	try {
		return client.inspectContainer(containerId);
	} catch (DockerException | InterruptedException e) {
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:ipedrazas,項目名稱:eclipse-docker-plugin,代碼行數:10,代碼來源:DockerUtils.java

示例4: foo

import com.spotify.docker.client.DockerClient; //導入方法依賴的package包/類
private static void foo() throws Exception {
    boolean debug = Boolean.parseBoolean(System.getProperty("debug", "false"));
    String dockerHost = String.format("http://%s:%d", CENTOS, 2375);
    DockerClient docker = null;
    try {
        docker = DefaultDockerClient.builder()
            .uri(dockerHost).build();
        Info info = docker.info();
        System.err.println("Information : " + info);
        if (debug) {
            docker.pull(SELENIUM_STANDALONE_CHROME, new LoggingBuildHandler());
        } else {
            docker.pull(SELENIUM_STANDALONE_CHROME);
        }
        final ImageInfo imageInfo = docker.inspectImage(SELENIUM_STANDALONE_CHROME);
        System.err.println("Information : " + imageInfo);
        // Bind container ports to host ports
        //            final String[] ports = {Integer.toString(PortProber.findFreePort())};
        final String[] ports = {"4444"};
        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", PortProber.findFreePort()));
            portBindings.put(port, hostPorts);
        }
        //            // Bind container port 443 to an automatically allocated available host port.
        //            List<PortBinding> randomPort = new ArrayList<>();
        //            randomPort.add(PortBinding.randomPort("0.0.0.0"));
        //            portBindings.put("443", randomPort);

        System.err.println("Printing the port mappings : " + portBindings);

        final HostConfig hostConfig = HostConfig.builder().portBindings(portBindings).build();

        final ContainerConfig containerConfig = ContainerConfig.builder()
            .hostConfig(hostConfig)
            .image(SELENIUM_STANDALONE_CHROME).exposedPorts(ports)
            .build();

        final ContainerCreation creation = docker.createContainer(containerConfig);
        final String id = creation.id();

        // Inspect container
        final ContainerInfo containerInfo = docker.inspectContainer(id);
        System.err.println("Container Information " + containerInfo);
        String msg = "Checking to see if the container with id [" + id + "] and name [" +
            containerInfo.name() + "]...";
        System.err.println(msg);
        if (! containerInfo.state().running()) {
            // Start container
            docker.startContainer(id);
            System.err.println(containerInfo.name() + " is now running.");
        } else {
            System.err.println(containerInfo.name() + " was already running.");
        }

        System.err.println("Lets wait here !!!");
    } finally {
        if (docker != null) {
            docker.close();
        }
    }
}
 
開發者ID:RationaleEmotions,項目名稱:just-ask,代碼行數:64,代碼來源:DockerSample.java

示例5: cleanup

import com.spotify.docker.client.DockerClient; //導入方法依賴的package包/類
private void cleanup(DockerClient dockerClient, String containerId) throws DockerException, InterruptedException {
    try {
        if (containerExists(dockerClient, containerId)) {
            ContainerInfo containerInfo = dockerClient.inspectContainer(containerId);
            if (containerInfo.state().running()) {
                dockerClient.killContainer(containerId);
            }
            dockerClient.removeContainer(containerId, DockerClient.RemoveContainerParam.removeVolumes());
        }
    } catch (DockerRequestException dockerRequestException) {
        throw new IllegalStateException(dockerRequestException.message(), dockerRequestException);
    }
}
 
開發者ID:tdomzal,項目名稱:junit-docker-rule,代碼行數:14,代碼來源:DockerRuleStopOptionsTest.java

示例6: run

import com.spotify.docker.client.DockerClient; //導入方法依賴的package包/類
@Override
		protected IStatus run(IProgressMonitor monitorParam) {

			SubMonitor monitor = SubMonitor.convert(monitorParam, 100);

			Status status = null;

			try {
				if(servicesToCreate != null){
					DockerConnectionElement dockerConnElem = cloudServer.getDockerConnElem();
					DockerClient dockerClient = null;
					if(dockerConnElem != null){
						dockerClient = dockerConnElem.getDockerClient();
					}
					if (dockerClient != null) {
						String containerId = cloudServer.getDockerContainerId();
						ContainerInfo containerInfo = dockerClient.inspectContainer(containerId);
						DockerContainerInfo dockerContainerInfo = DockerDomainHelper.getDockerInfo(containerInfo);
						
						List<String> binds = containerInfo.hostConfig().binds();
//						List<String> binds = containerInfo.hostConfig().links();
						List<String> links = new ArrayList<String>();
//						binds.add(volume);
						
						for (List<ServiceInstance> list : servicesToCreate) {
							for (ServiceInstance serviceInstance : list) {
								String name = serviceInstance.getName();
								String label = serviceInstance.getUserDefinedName();
								links.add(name +":" + label);
							}
						}
						HostConfig expected = HostConfig.builder().privileged(true).binds(binds).links(links)
								.publishAllPorts(true).build();
						
						if(dockerContainerInfo.getRunning()){
							dockerClient.stopContainer(containerId, 60);
							Thread.sleep(5000);
						}
						dockerClient.startContainer(containerId, expected);
					}
				}
//				for (CloudService cs : servicesToCreate) {
//					cloudServer.getBehaviour().operations().createServices((new CloudService[] { cs }))
//							.run(monitor.newChild(100));
//				}

				monitor.worked(100);

			}
			catch (Exception e) {
				status = new Status(IStatus.ERROR, DockerFoundryPlugin.PLUGIN_ID, NLS.bind(
						Messages.DockerFoundryServiceWizard_ERROR_ADD_SERVICE,
						cloudServer.getServer().getName(),
						e.getCause() != null && e.getCause().getMessage() != null ? e.getCause().getMessage() : e
								.toString()), e);
			}

			monitor.done();

			if (status != null && !status.isOK()) {
				final IStatus statusToDisplay = status;
				Display.getDefault().asyncExec(new Runnable() {

					@Override
					public void run() {
						StatusManager.getManager().handle(statusToDisplay,
								StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
					}
				});
				return Status.CANCEL_STATUS;
			}

			return Status.OK_STATUS;
		}
 
開發者ID:osswangxining,項目名稱:dockerfoundry,代碼行數:75,代碼來源:DockerFoundryServiceWizard.java

示例7: deployServer

import com.spotify.docker.client.DockerClient; //導入方法依賴的package包/類
public static boolean deployServer(Server server) {
    Credentials mongoCreds = MineCloud.instance().mongo().credentials();
    Credentials redisCreds = MineCloud.instance().redis().credentials();
    String name = server.type().name() + server.number();
    World defaultWorld = server.type().defaultWorld();
    ContainerConfig config = ContainerConfig.builder()
            .hostname(name)
            .image("minecloud/server")
            .openStdin(true)
            .env(new EnvironmentBuilder()
                    .append("mongo_hosts", mongoCreds.formattedHosts())
                    .append("mongo_username", mongoCreds.username())
                    .append("mongo_password", new String(mongoCreds.password()))
                    .append("mongo_database", mongoCreds.database())

                    .append("redis_host", redisCreds.hosts()[0])
                    .append("redis_password", new String(redisCreds.password()))
                    .append("SERVER_MOD", server.type().mod())
                    .append("DEDICATED_RAM", String.valueOf(server.type().dedicatedRam()))
                    .append("MAX_PLAYERS", String.valueOf(server.type().maxPlayers()))

                    .append("server_id", server.entityId())
                    .append("DEFAULT_WORLD", defaultWorld.name())
                    .append("DEFAULT_WORLD_VERSION", defaultWorld.version())
                    .build())
            .build();

    ContainerCreation creation;

    try {
        DockerClient client = MineCloudDaemon.instance().dockerClient();

        try {
            ContainerInfo info = client.inspectContainer(name);

            if (info.state().running()) {
                client.killContainer(name);
            }

            client.removeContainer(info.id());
        } catch (ContainerNotFoundException ignored) {}

        creation = client.createContainer(config, name);

        client.startContainer(creation.id(), HostConfig.builder()
                .binds("/mnt/minecloud:/mnt/minecloud")
                .publishAllPorts(true)
                .build());
    } catch (InterruptedException | DockerException ex) {
        MineCloud.logger().log(Level.SEVERE, "Was unable to create server with type " + server.type().name(),
                ex);
        return false;
    }

    MineCloud.logger().info("Started server " + server.name()
            + " with container id " + server.containerId());
    return true;
}
 
開發者ID:mkotb,項目名稱:MineCloud,代碼行數:59,代碼來源:Deployer.java

示例8: deployBungeeCord

import com.spotify.docker.client.DockerClient; //導入方法依賴的package包/類
public static Bungee deployBungeeCord(Network network, BungeeType type) {
    DockerClient client = MineCloudDaemon.instance().dockerClient();
    BungeeRepository repository = MineCloud.instance().mongo().repositoryBy(Bungee.class);
    Node node = MineCloudDaemon.instance().node();
    Bungee bungee = new Bungee();

    if (repository.count("_id", node.publicIp()) > 0) {
        MineCloud.logger().log(Level.WARNING, "Did not create bungee on this node; public ip is already in use");
        return null;
    }

    bungee.setId(node.publicIp());

    Credentials mongoCreds = MineCloud.instance().mongo().credentials();
    Credentials redisCreds = MineCloud.instance().redis().credentials();
    ContainerConfig config = ContainerConfig.builder()
            .image("minecloud/bungee")
            .hostname("bungee" + bungee.publicIp())
            .exposedPorts("25565")
            .openStdin(true)
            .env(new EnvironmentBuilder()
                    .append("mongo_hosts", mongoCreds.formattedHosts())
                    .append("mongo_username", mongoCreds.username())
                    .append("mongo_password", new String(mongoCreds.password()))
                    .append("mongo_database", mongoCreds.database())

                    .append("redis_host", redisCreds.hosts()[0])
                    .append("redis_password", new String(redisCreds.password()))
                    .append("DEDICATED_RAM", String.valueOf(type.dedicatedRam()))

                    .append("bungee_id", node.publicIp())
                    .build())
            .build();
    HostConfig hostConfig = HostConfig.builder()
            .binds("/mnt/minecloud:/mnt/minecloud")
            .portBindings(new HashMap<String, List<PortBinding>>() {{
                put("25565", Arrays.asList(PortBinding.of(node.publicIp(), 25565))); // I'm sorry
            }})
            .publishAllPorts(true)
            .build();

    try {
        ContainerInfo info = client.inspectContainer("bungee");

        if (info.state().running()) {
            client.killContainer("bungee");
        }

        client.removeContainer(info.id());
    } catch (DockerException | InterruptedException ignored) {}

    ContainerCreation creation;

    try {
        creation = client.createContainer(config, type.name());

        client.startContainer(creation.id(), hostConfig);
    } catch (InterruptedException | DockerException ex) {
        MineCloud.logger().log(Level.SEVERE, "Was unable to create bungee with type " + type.name(),
                ex);
        return bungee;
    }

    bungee.setNetwork(network);
    bungee.setNode(node);
    bungee.setPublicIp(node.publicIp());
    bungee.setType(type);

    repository.save(bungee);
    MineCloud.logger().info("Started bungee " + bungee.name() + " with container id " + bungee.containerId());
    return bungee;
}
 
開發者ID:mkotb,項目名稱:MineCloud,代碼行數:73,代碼來源:Deployer.java


注:本文中的com.spotify.docker.client.DockerClient.inspectContainer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。