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());
}
Aggregations