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


Java HostConfig类代码示例

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


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

示例1: newContainer

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

示例2: PostgresContainer

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

示例3: init

import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
@Override
public void init() throws Exception {
    Assume.assumeTrue(DockerTestUtils.isDockerAvailable());

    this.creds = new DockerRegistryCredentials(
        "127.0.0.1:5000",
        "",
        "",
        "testing"
    );

    DockerClient client = DefaultDockerClient.fromEnv().build();
    logger.info("Downloading registry image");
    client.pull("registry:2");

    final Map<String, List<PortBinding>> ports = singletonMap(
        "5000/tcp", Collections.singletonList(PortBinding.of("0.0.0.0", 5000)));
    final HostConfig hostConfig = HostConfig.builder().portBindings(ports)
        .build();

    logger.info("Creating Local Registry Container");
    ContainerConfig config = ContainerConfig.builder()
        .hostConfig(hostConfig)
        .image("registry:2").build();
    String id = client.createContainer(config).id();
    logger.info("Registry container id: {}", id);

    logger.info("Starting registry container");
    client.startContainer(id);
    this.registryid = id;
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:32,代码来源:PushingImageBuilderIT.java

示例4: createContainer

import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
public String createContainer(String image, Path volume) throws DockerException, InterruptedException {
	ContainerConfig containerConfig = ContainerConfig.builder()
			.image(image)
			.workingDir("/sandbox")
			.hostConfig(
					HostConfig.builder().binds(HostConfig.Bind.builder().from(volume.toString()).to("/sandbox").build()).build()
			).cmd("sh", "-c", "while :; do sleep 1; done")
			.build();
	return createContainer(containerConfig);
}
 
开发者ID:ProgramLeague,项目名称:Avalon-Executive,代码行数:11,代码来源:DockerOperator.java

示例5: prepareContainer

import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
/**
 * create container running configuration from running task
 *
 * @param task
 *
 * @return
 */
private ContainerConfig prepareContainer(Task task) {
    final String functionName = task.getName();
    final String language = task.getLanguage();

    final DockerConfig dockerConfig = config.getDockers().get(language);
    final Map<String, String> labels = new HashMap<>();
    labels.put(LABEL_DSHELL_FUNCTION, functionName);
    final Path path = Paths.get(task.getArtifact().getPath()).getParent();
    List<String> binds = new ArrayList<>();
    if (task.getDind() == Boolean.TRUE) {
        binds.add(String.format("%s:%s:rw", DOCKER_SOCK_FIEL, DOCKER_SOCK_FIEL));
    }
    if (StringUtils.isNotBlank(task.getVolumes())) {
        binds.addAll(Arrays.asList(task.getVolumes().trim().split(",")));
    }
    binds.add(String.format("%s:%s:rw", path, Constants.SCRIPTS_DIRE));
    final HostConfig hostConfig = HostConfig.builder()
                                            .binds(binds)
                                            .publishAllPorts(true)
                                            .build();
    return ContainerConfig.builder()
                          .image(dockerConfig.getImage())
                          .labels(labels)
                          .hostConfig(hostConfig)
                          .build();
}
 
开发者ID:dshell-io,项目名称:dshell,代码行数:34,代码来源:LocalEngine.java

示例6: create

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

示例7: addLxcParameter

import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
@Override
public RxDeployment addLxcParameter(String key, String value) {
	LinkedList<HostConfig.LxcConfParameter> list = new LinkedList<>();
	list.add(new HostConfig.LxcConfParameter(key, value));
	
	if (this.hostConfig.lxcConf()!= null) {
		list.addAll(this.hostConfig.lxcConf());
	}
	this.hostConfig.lxcConf(list);
	return this;
}
 
开发者ID:petercipov,项目名称:mobi,代码行数:12,代码来源:SpotifyOptions.java

示例8: before

import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
@Override
protected void before() throws Throwable {
  // Create a client based on DOCKER_HOST and DOCKER_CERT_PATH env vars
  docker = DefaultDockerClient.fromEnv().build();
  hostName = docker.getHost();
  docker.pull(POSTGRES_9_2_IMAGE);
  // Bind container ports to host ports
  localPort = NetworkUtils.findAvailablePort();
  final HostConfig hostConfig = HostConfig.builder()
      .portBindings(createPortBinding(POSTGRESQL_PORT, localPort))
      .build();
  this.container = docker.createContainer(ContainerConfig.builder()
      .image(POSTGRES_9_2_IMAGE)
      .hostConfig(hostConfig)
      .exposedPorts(String.valueOf(POSTGRESQL_PORT))
      .build());
  docker.startContainer(container.id());
  waitForDatabase(RETRIES);
  createDatabase();
  Flyway flyway = new Flyway();
  flyway.setSqlMigrationPrefix("v");
  flyway.setSqlMigrationSeparator("-");
  flyway.setDataSource(getDataSource(databaseName));
  flyway.migrate();
  for (String script : scripts) {
    executeScript(script);
  }
}
 
开发者ID:cs71-caffeine,项目名称:awesome-agile,代码行数:29,代码来源:TestDatabase.java

示例9: buildContainerConfig

import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
@Override
public ContainerConfig buildContainerConfig(ContainerRequest request, String ownerUsername,
                                            UriComponentsBuilder requestUri)
        throws MccyException, DockerException, InterruptedException {
    final int requestedPort = request.getPort();
    PortBinding portBinding = PortBinding.of("",
            requestedPort != 0 ? String.valueOf(requestedPort) : "");
    Map<String, List<PortBinding>> portBindings =
            singletonMap(MccyConstants.SERVER_CONTAINER_PORT, singletonList(portBinding));

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

    final ArrayList<String> env = new ArrayList<>();

    fillAssetsLinkage(hostConfig, env, request, requestUri);

    return ContainerConfig.builder()
            .attachStdin(true)
            .tty(true)
            .exposedPorts(MccyConstants.SERVER_CONTAINER_PORT)
            .env(fillEnv(env, request))
            .image(mccySettings.getImage())
            .hostConfig(hostConfig.build())
            .labels(buildLabels(request, ownerUsername))
            .build();

}
 
开发者ID:moorkop,项目名称:mccy-engine,代码行数:29,代码来源:ContainerBuilderServiceImpl.java

示例10: startContainer

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

示例11: updateContainer

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

示例12: SpotifyOptions

import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
public SpotifyOptions(SpotifyRxDocker docker) {
      this.containerConfig = ContainerConfig.builder();
this.hostConfig = HostConfig.builder();
this.docker = docker;
  }
 
开发者ID:petercipov,项目名称:mobi,代码行数:6,代码来源:SpotifyOptions.java

示例13: RestartPolicy

import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
public RestartPolicy(HostConfig.RestartPolicy restartPolicy) {
    this.restartPolicy = restartPolicy;
}
 
开发者ID:tdomzal,项目名称:junit-docker-rule,代码行数:4,代码来源:RestartPolicy.java

示例14: getRestartPolicy

import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
public HostConfig.RestartPolicy getRestartPolicy() {
    return restartPolicy;
}
 
开发者ID:tdomzal,项目名称:junit-docker-rule,代码行数:4,代码来源:RestartPolicy.java

示例15: unlessStopped

import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
/**
 * 'unlessStopped' restart policy.
 */
public static RestartPolicy unlessStopped() {
    return new RestartPolicy(HostConfig.RestartPolicy.unlessStopped());
}
 
开发者ID:tdomzal,项目名称:junit-docker-rule,代码行数:7,代码来源:RestartPolicy.java


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