Search in sources :

Example 1 with Builder

use of com.spotify.docker.client.messages.HostConfig.Builder in project shinyproxy by openanalytics.

the class DockerEngineBackend method prepareProxy.

@Override
protected void prepareProxy(DockerContainerProxy proxy, ContainerProxyRequest request) throws Exception {
    Builder hostConfigBuilder = HostConfig.builder();
    List<PortBinding> portBindings = Collections.emptyList();
    if (proxy.getPort() > 0)
        portBindings = Collections.singletonList(PortBinding.of("0.0.0.0", proxy.getPort()));
    hostConfigBuilder.portBindings(Collections.singletonMap(String.valueOf(getAppPort(proxy)), portBindings));
    Optional.ofNullable(Utils.memoryToBytes(request.app.getDockerMemory())).ifPresent(l -> hostConfigBuilder.memory(l));
    Optional.ofNullable(request.app.getDockerNetwork()).ifPresent(n -> hostConfigBuilder.networkMode(request.app.getDockerNetwork()));
    hostConfigBuilder.dns(request.app.getDockerDns());
    hostConfigBuilder.binds(getBindVolumes(request.app));
    hostConfigBuilder.privileged(Boolean.valueOf(getProperty(PROPERTY_PRIVILEGED, request.app, DEFAULT_PRIVILEGED)));
    ContainerConfig containerConfig = ContainerConfig.builder().hostConfig(hostConfigBuilder.build()).image(request.app.getDockerImage()).exposedPorts(String.valueOf(getAppPort(proxy))).cmd(request.app.getDockerCmd()).env(buildEnv(request.userId, request.app)).build();
    ContainerCreation container = dockerClient.createContainer(containerConfig);
    proxy.setContainerId(container.id());
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) ContainerCreation(com.spotify.docker.client.messages.ContainerCreation) PortBinding(com.spotify.docker.client.messages.PortBinding) Builder(com.spotify.docker.client.messages.HostConfig.Builder)

Aggregations

ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)1 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)1 Builder (com.spotify.docker.client.messages.HostConfig.Builder)1 PortBinding (com.spotify.docker.client.messages.PortBinding)1