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


Java HostConfig.Builder方法代码示例

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


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

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

示例2: fillAssetsLinkage

import com.spotify.docker.client.messages.HostConfig; //导入方法依赖的package包/类
private void fillAssetsLinkage(HostConfig.Builder hostConfig, ArrayList<String> env,
                               ContainerRequest request, UriComponentsBuilder requestUri) {
    boolean builtLink = false;
    if (ourContainerId != null && needsLink(request)) {
        hostConfig.links(ourContainerId + ":" + MccyConstants.LINK_MCCY);
        builtLink = true;
    }

    final List<AssetRef> assets = request.getAssets();
    if (assets == null || assets.isEmpty()) {
        return;
    }

    final Optional<AssetRef> worldAssetRef = assets.stream()
            .filter(assetRef -> assetRef.getCategory() == AssetCategory.WORLD)
            .findFirst();

    if (worldAssetRef.isPresent()) {
        final UriComponents builtUri;
        switch (mccyAssetSettings.getVia()) {
            case NETWORK:
                builtUri = UriComponentsBuilder.newInstance()
                        .scheme("http")
                        .host(mccyAssetSettings.getMyNameOnNetwork())
                        .port(getOurPort())
                        .path(ApiAssetsController.ASSET_DOWNLOAD_PATH)
                        .path(WORLD_ZIP_NAME)
                        .build();
                hostConfig.networkMode(mccyAssetSettings.getNetwork());
                break;

            case FIXED_URI:
                builtUri = UriComponentsBuilder
                        .fromUri(mccyAssetSettings.getFixedUri())
                        .path(ApiAssetsController.ASSET_DOWNLOAD_PATH)
                        .path(WORLD_ZIP_NAME)
                        .build();
                break;

            case LINK:
                builtUri = UriComponentsBuilder.newInstance()
                        .scheme("http")
                        .host(MccyConstants.LINK_MCCY)
                        .port(getOurPort())
                        .path(ApiAssetsController.ASSET_DOWNLOAD_PATH)
                        .path(WORLD_ZIP_NAME)
                        .build();
                if (!builtLink) {
                    hostConfig.links(ourContainerId + ":" + MccyConstants.LINK_MCCY);
                }
                break;

            default:
            case REQUEST_URL:
                builtUri = ((UriComponentsBuilder) requestUri.clone())
                        .replacePath(ApiAssetsController.ASSET_DOWNLOAD_PATH)
                        .path(WORLD_ZIP_NAME)
                        .build();
                break;
        }

        env.add(MccyConstants.ENV_WORLD + "=" +
                builtUri.expand(AssetCategory.WORLD, worldAssetRef.get().getId()));
    }
}
 
开发者ID:moorkop,项目名称:mccy-engine,代码行数:66,代码来源:ContainerBuilderServiceImpl.java


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