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


Java DockerException类代码示例

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


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

示例1: PostgresContainer

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
public  PostgresContainer(DockerClient docker, String host) throws InterruptedException, IOException, ClassNotFoundException, DockerException {
    Class.forName("org.postgresql.Driver");

    this.docker = docker;
    this.host = host;

    failsafeDockerPull(docker, GOVUK_POSTGRES_IMAGE);
    docker.listImages(DockerClient.ListImagesParam.create("name", GOVUK_POSTGRES_IMAGE));

    final HostConfig hostConfig = HostConfig.builder().logConfig(LogConfig.create("json-file")).publishAllPorts(true).build();
    ContainerConfig containerConfig = ContainerConfig.builder()
            .image(GOVUK_POSTGRES_IMAGE)
            .hostConfig(hostConfig)
            .env("POSTGRES_USER=" + DB_USERNAME, "POSTGRES_PASSWORD=" + DB_PASSWORD)
            .build();
    containerId = docker.createContainer(containerConfig).id();
    docker.startContainer(containerId);
    port = hostPortNumber(docker.inspectContainer(containerId));
    registerShutdownHook();
    waitForPostgresToStart();
}
 
开发者ID:alphagov,项目名称:pay-adminusers,代码行数:22,代码来源:PostgresContainer.java

示例2: newContainer

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
@Override
String newContainer(Language language) throws DockerException, InterruptedException {
	String name = language.getRunDockerImageName();
	if (!DockerOperator.instance().isImageExist(name))
		DockerOperator.instance().pull(name);
	ContainerConfig config = ContainerConfig.builder()
			.networkDisabled(true)
			.workingDir("/sandbox")
			.image(name)
			.cmd("sh", "-c", "while :; do sleep 1; done")
			.hostConfig(
					HostConfig.builder().binds(HostConfig.Bind.builder()
							.from(Constants._WORK_DIR()).to("/sandbox").build())
							.oomKillDisable(false).memory(67108864L).memorySwap(67108864L).build()
			).build();
	String r = DockerOperator.instance().createContainer(config);
	map.put(language, r);
	return r;
}
 
开发者ID:ProgramLeague,项目名称:Avalon-Executive,代码行数:20,代码来源:RunContainerPool.java

示例3: exec

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
public ExecPair exec(String containerId, String cmd) throws DockerException, InterruptedException, IOException {
	final String execId = client.execCreate(
			containerId,
			cmd.split(" "),
			ExecCreateParam.attachStdout(),
			ExecCreateParam.tty())
			.id();
	SafetyOutputStream outputStream = new SafetyOutputStream();
	try (final LogStream stream = client.execStart(execId)) {
		stream.attach(outputStream, outputStream);
	}
	LOGGER.info("execute cmd to container successful - execId: " + execId);
	String r = outputStream.get();
	return new ExecPair(execId, r
			.replace("\r", "")
			.replace("\n", " ")
	);
}
 
开发者ID:ProgramLeague,项目名称:Avalon-Executive,代码行数:19,代码来源:DockerOperator.java

示例4: run

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
public static ExecPair run(Language language, Submission submission)
		throws DockerException, InterruptedException, RunErrorException, IOException {
	String containerId = RunContainerPool.instance().getContainerId(language);
	ExecPair state = instance().exec(containerId, language.getRunCmd().replace("_file", String.valueOf(submission.getSubmitTime())));

	Thread.sleep(_TIME_LIMIT_MILLISECONDS);

	ExecInfoSimple info = instance().inspectExec(state.getExecId());

	if (info.isRunning())
		throw new RunErrorException("<out of time>");

	ContainerState containerState = instance().inspectContainer(containerId);
	if (containerState == null)
		throw new RuntimeException();
	Boolean oomKilled = containerState.oomKilled();
	if (oomKilled != null && oomKilled)
		throw new RunErrorException("<out of resources>");
	if (!containerState.running())
		throw new RunErrorException("<unknown error>");
	return state;
}
 
开发者ID:ProgramLeague,项目名称:Avalon-Executive,代码行数:23,代码来源:Runner.java

示例5: compile

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
public static File compile(Submission submission)
		throws DockerException, InterruptedException, IOException, CompileErrorException {
	Language language = submission.getLanguage();
	String cmd = language.getCompileCmd().replace("_file", String.valueOf(submission.getSubmitTime()));
	String executableSuffix = getCodeFileSuffix(cmd);
	File executableFile = new File(String.format("%s/%s.%s", Constants._WORK_DIR(), submission.getSubmitTime(), executableSuffix));

	if (!language.isCompileNeeded())
		return executableFile;

	String containerId = CompilerContainerPool.instance().getContainerId(language);

	ExecPair state = DockerOperator.instance().exec(containerId, cmd);
	ExecInfoSimple info = DockerOperator.instance().inspectExec(state.getExecId());
	if (info.getExitCode() != 0)
		throw new CompileErrorException(state);

	return executableFile;
}
 
开发者ID:ProgramLeague,项目名称:Avalon-Executive,代码行数:20,代码来源:Compiler.java

示例6: create

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的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

示例7: followLogs

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
@Override
public void followLogs(final String containerId, final Logger logger) {
    logger.info("********** Container logs **********");
    try {
        final LogStream logs = this.client.logs(
            containerId,
            DockerClient.LogsParam.stdout(),
            DockerClient.LogsParam.stderr(),
            DockerClient.LogsParam.follow()
        );
        logger.info(logs.readFully());
    } catch (final DockerException | InterruptedException ex) {
        throw new IllegalStateException(
            "Exception when starting container with id " + containerId, ex
        );
    }
    logger.info("************************************");
}
 
开发者ID:amihaiemil,项目名称:comdor,代码行数:19,代码来源:RtDockerHost.java

示例8: predownloadImagesIfRequired

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
private static void predownloadImagesIfRequired() throws DockerException, InterruptedException {

        DockerClient client = getClient();
        LOG.warning("Commencing download of images.");
        Collection<MappingInfo> images = getInstance().getMapping().values();

        ProgressHandler handler = new LoggingBuildHandler();
        for (MappingInfo image : images) {
            List<Image> foundImages = client.listImages(DockerClient.ListImagesParam.byName(image.getTarget()));
            if (! foundImages.isEmpty()) {
                LOG.warning(String.format("Skipping download for Image [%s] because it's already available.",
                    image.getTarget()));
                continue;
            }
            client.pull(image.getTarget(), handler);
        }
    }
 
开发者ID:RationaleEmotions,项目名称:just-ask,代码行数:18,代码来源:DockerHelper.java

示例9: getAccessToPort

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
/**
 * Obtains the access information for the requested containerPort
 * @param containerPort the port to locate according to the <code>EXPOSE</code>d/internal container port
 * @return a socket address populated with external host and port of the container
 * @throws DockerException if an issue occurred containing the Docker daemon
 * @throws InterruptedException if interrupted while contacting the Docker daemon
 */
public InetSocketAddress getAccessToPort(int containerPort) throws DockerException, InterruptedException {
    ContainerInfo containerInfo = dockerClient.inspectContainer(container.id());

    NetworkSettings networkSettings = containerInfo.networkSettings();

    List<PortBinding> portBindings = networkSettings.ports().get(String.format("%d/tcp", containerPort));
    if (portBindings != null && !portBindings.isEmpty()) {
        PortBinding portBinding = portBindings.get(0);

        return new InetSocketAddress(dockerClient.getHost(), Integer.parseInt(portBinding.hostPort()));
    }
    else {
        return null;
    }
}
 
开发者ID:itzg,项目名称:junit-rule-docker,代码行数:23,代码来源:DockerRule.java

示例10: stop

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
public void stop() {
    if (stopped) {
        return;
    }
    try {
        stopped = true;
        System.out.println("Killing postgres container with ID: " + containerId);
        LogStream logs = docker.logs(containerId, DockerClient.LogsParam.stdout(), DockerClient.LogsParam.stderr());
        System.out.println("Killed container logs:\n");
        logs.attach(System.out, System.err);
        docker.stopContainer(containerId, 5);
        docker.removeContainer(containerId);
    } catch (DockerException | InterruptedException | IOException e) {
        System.err.println("Could not shutdown " + containerId);
        e.printStackTrace();
    }
}
 
开发者ID:alphagov,项目名称:pay-adminusers,代码行数:18,代码来源:PostgresContainer.java

示例11: removeVolume

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
private static void removeVolume() throws Exception {
    if (dockerApiVersionAtLeast(docker, "1.26")) {
        if (docker.listVolumes().volumes() != null) {
            docker.listVolumes().volumes().forEach(volume -> {
                if (volume.labels() != null && volume.labels().containsKey("cd.go.contrib.elasticagents.dockerswarm.elasticagent.DockerPlugin")) {
                    try {
                        docker.removeVolume(volume.name());
                    } catch (DockerException | InterruptedException e) {
                    }
                }
            });
        }
    } else {
        LOG.warn(format("Detected docker version and api version is {0} and {1} respectively. Docker with api version 1.26 or above is required to use volume mounts, secrets and host file entries. Please refer https://docs.docker.com/engine/api/v1.32/#section/Versioning for more information about docker release.", docker.version().version(), docker.version().apiVersion()));
    }
}
 
开发者ID:gocd-contrib,项目名称:docker-swarm-elastic-agents,代码行数:17,代码来源:BaseTest.java

示例12: PostgresContainer

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
public PostgresContainer(DockerClient docker, String host) throws InterruptedException, IOException, ClassNotFoundException, DockerException {
    Class.forName("org.postgresql.Driver");

    this.docker = docker;
    this.host = host;

    failsafeDockerPull(docker, GOVUK_POSTGRES_IMAGE);
    docker.listImages(DockerClient.ListImagesParam.create("name", GOVUK_POSTGRES_IMAGE));

    final HostConfig hostConfig = HostConfig.builder().logConfig(LogConfig.create("json-file")).publishAllPorts(true).build();
    ContainerConfig containerConfig = ContainerConfig.builder()
            .image(GOVUK_POSTGRES_IMAGE)
            .hostConfig(hostConfig)
            .env("POSTGRES_USER=" + DB_USERNAME, "POSTGRES_PASSWORD=" + DB_PASSWORD)
            .build();
    containerId = docker.createContainer(containerConfig).id();
    docker.startContainer(containerId);
    port = hostPortNumber(docker.inspectContainer(containerId));
    registerShutdownHook();
    waitForPostgresToStart();
}
 
开发者ID:alphagov,项目名称:pay-publicauth,代码行数:22,代码来源:PostgresContainer.java

示例13: stop

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
public void stop() {
    if (stopped) {
        return;
    }
    try {
        stopped = true;
        System.err.println("Killing postgres container with ID: " + containerId);
        LogStream logs = docker.logs(containerId, DockerClient.LogsParam.stdout(), DockerClient.LogsParam.stderr());
        System.err.println("Killed container logs:\n");
        logs.attach(System.err, System.err);
        docker.stopContainer(containerId, 5);
        docker.removeContainer(containerId);
    } catch (DockerException | InterruptedException | IOException e) {
        System.err.println("Could not shutdown " + containerId);
        e.printStackTrace();
    }
}
 
开发者ID:alphagov,项目名称:pay-publicauth,代码行数:18,代码来源:PostgresContainer.java

示例14: after

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
/**
 * Stop and remove container.<br/>
 * This is {@link ExternalResource#before()} made available as public - it may be helpful in scenarios
 * when you want to use {@link DockerRule} and operate it manually.
 */
@Override
public final void after() {
    log.debug("after {}", containerShortId);
    try {
        dockerLogs.close();
        ContainerState state = dockerClient.inspectContainer(container.id()).state();
        log.debug("{} state {}", containerShortId, state);
        if (state.running()) {
            if (builder.stopOptions().contains(StopOption.KILL)) {
                dockerClient.killContainer(container.id());
                log.info("{} killed", containerShortId);
            } else {
                dockerClient.stopContainer(container.id(), STOP_TIMEOUT);
                log.info("{} stopped", containerShortId);
            }
        }
        if (builder.stopOptions().contains(StopOption.REMOVE)) {
            dockerClient.removeContainer(container.id(), DockerClient.RemoveContainerParam.removeVolumes());
            log.info("{} deleted", containerShortId);
            container = null;
        }
    } catch (DockerException | InterruptedException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:tdomzal,项目名称:junit-docker-rule,代码行数:31,代码来源:DockerRule.java

示例15: shouldRestartAfterEnd

import com.spotify.docker.client.exceptions.DockerException; //导入依赖的package包/类
@Test
public void shouldRestartAfterEnd() throws InterruptedException, IOException, DockerException {
    final String initialStartedUp = testee.getDockerClient().inspectContainer(testee.getContainerId()).state().startedAt().toString();
    new WaitForUnit(TimeUnit.SECONDS, 10, new WaitForUnit.WaitForCondition() {
        @Override
        public boolean isConditionMet() {
            try {
                String currentStartedAt = testee.getDockerClient().inspectContainer(testee.getContainerId()).state().startedAt().toString();
                log.debug("(initial) '{}' != (current) '{}' ?", initialStartedUp, currentStartedAt);
                return ! initialStartedUp.equals(currentStartedAt);
            } catch (DockerException | InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    });
}
 
开发者ID:tdomzal,项目名称:junit-docker-rule,代码行数:17,代码来源:DockerRuleRestartPolicyTest.java


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