extraHosts.addAll(hubExtraHosts); HostConfig.Builder hostConfigBuilder = HostConfig.builder() .appendBinds(binds) .networkMode(networkMode)
Builder(HostConfig source) { this.binds = source.binds(); this.blkioWeight = source.blkioWeight(); this.blkioWeightDevice = source.blkioWeightDevice(); this.blkioDeviceReadBps = source.blkioDeviceReadBps(); this.blkioDeviceWriteBps = source.blkioDeviceWriteBps(); this.blkioDeviceReadIOps = source.blkioDeviceReadIOps(); this.blkioDeviceWriteIOps = source.blkioDeviceWriteIOps(); this.containerIdFile = source.containerIdFile(); this.lxcConf = source.lxcConf(); this.privileged = source.privileged(); this.portBindings = source.portBindings(); this.links = source.links(); this.publishAllPorts = source.publishAllPorts(); this.dns = source.dns(); this.dnsOptions = source.dnsOptions(); this.dnsSearch = source.dnsSearch(); this.extraHosts = source.extraHosts(); this.groupAdd = source.groupAdd(); this.volumesFrom = source.volumesFrom(); this.capAdd = source.capAdd(); this.capDrop = source.capDrop(); this.networkMode = source.networkMode(); this.securityOpt = source.securityOpt(); this.devices = source.devices(); this.memory = source.memory(); this.memorySwap = source.memorySwap(); this.kernelMemory = source.kernelMemory(); this.memorySwappiness = source.memorySwappiness(); this.memoryReservation = source.memoryReservation();
docker.inspectContainer(taskStatus.getContainerId()).hostConfig(); assertEquals(CPU_SHARES, hostConfig.cpuShares()); assertEquals(CPUSET_CPUS, hostConfig.cpusetCpus()); assertEquals(MEMORY, hostConfig.memory()); assertEquals(MEMORY_SWAP, hostConfig.memorySwap());
public HostConfig build() { final HostConfig hostConfig = autoBuild(); validateExtraHosts(hostConfig.extraHosts()); return hostConfig; } }
@Override public void decorateHostConfig(Job job, Optional<String> dockerVersion, HostConfig.Builder hostConfigBuilder) { final List<String> b = Lists.newArrayList(); final HostConfig hostConfig = hostConfigBuilder.build(); if (hostConfig.binds() != null) { b.addAll(hostConfig.binds()); } b.addAll(this.binds); hostConfigBuilder.binds(b); }
private synchronized List<String> getContainerExtraHosts(String zaleniumContainerName) { if (zaleniumExtraHosts != null) { return zaleniumExtraHosts; } String containerId = getContainerId(zaleniumContainerName); ContainerInfo containerInfo; try { containerInfo = dockerClient.inspectContainer(containerId); zaleniumExtraHosts = containerInfo.hostConfig().extraHosts(); } catch (DockerException | InterruptedException | NullPointerException e) { logger.debug(nodeId + " Error while getting Zalenium extra hosts.", e); ga.trackException(e); } return Optional.ofNullable(zaleniumExtraHosts).orElse(new ArrayList<>()); }
@Override public void decorateHostConfig(Job job, Optional<String> dockerVersion, HostConfig.Builder hostConfigBuilder) { final HostConfig hostConfig = hostConfigBuilder.build(); if (useSyslogRedirector(dockerVersion)) { final List<String> binds = Lists.newArrayList(); if (hostConfig.binds() != null) { binds.addAll(hostConfig.binds()); } binds.add("/usr/lib/helios:/helios:ro"); hostConfigBuilder.binds(binds); } else { final ImmutableMap.Builder<String, String> logOpts = ImmutableMap.builder(); logOpts.put("syslog-address", "udp://" + syslogHostPort); logOpts.put("syslog-facility", "local0"); // match the behavior of syslog-redirector logOpts.put("tag", job.getId().toString()); hostConfigBuilder.logConfig(LogConfig.create("syslog", logOpts.build())); } }
return ((this.binds == null) ? (that.binds() == null) : this.binds.equals(that.binds())) && ((this.blkioWeight == null) ? (that.blkioWeight() == null) : this.blkioWeight.equals(that.blkioWeight())) && ((this.blkioWeightDevice == null) ? (that.blkioWeightDevice() == null) : this.blkioWeightDevice.equals(that.blkioWeightDevice())) && ((this.blkioDeviceReadBps == null) ? (that.blkioDeviceReadBps() == null) : this.blkioDeviceReadBps.equals(that.blkioDeviceReadBps())) && ((this.blkioDeviceWriteBps == null) ? (that.blkioDeviceWriteBps() == null) : this.blkioDeviceWriteBps.equals(that.blkioDeviceWriteBps())) && ((this.blkioDeviceReadIOps == null) ? (that.blkioDeviceReadIOps() == null) : this.blkioDeviceReadIOps.equals(that.blkioDeviceReadIOps())) && ((this.blkioDeviceWriteIOps == null) ? (that.blkioDeviceWriteIOps() == null) : this.blkioDeviceWriteIOps.equals(that.blkioDeviceWriteIOps())) && ((this.containerIdFile == null) ? (that.containerIdFile() == null) : this.containerIdFile.equals(that.containerIdFile())) && ((this.lxcConf == null) ? (that.lxcConf() == null) : this.lxcConf.equals(that.lxcConf())) && ((this.privileged == null) ? (that.privileged() == null) : this.privileged.equals(that.privileged())) && ((this.portBindings == null) ? (that.portBindings() == null) : this.portBindings.equals(that.portBindings())) && ((this.links == null) ? (that.links() == null) : this.links.equals(that.links())) && ((this.publishAllPorts == null) ? (that.publishAllPorts() == null) : this.publishAllPorts.equals(that.publishAllPorts())) && ((this.dns == null) ? (that.dns() == null) : this.dns.equals(that.dns())) && ((this.dnsOptions == null) ? (that.dnsOptions() == null) : this.dnsOptions.equals(that.dnsOptions())) && ((this.dnsSearch == null) ? (that.dnsSearch() == null) : this.dnsSearch.equals(that.dnsSearch())) && ((this.extraHosts == null) ? (that.extraHosts() == null) : this.extraHosts.equals(that.extraHosts())) && ((this.groupAdd == null) ? (that.groupAdd() == null) : this.groupAdd.equals(that.groupAdd())) && ((this.volumesFrom == null) ? (that.volumesFrom() == null) : this.volumesFrom.equals(that.volumesFrom())) && ((this.capAdd == null) ? (that.capAdd() == null) : this.capAdd.equals(that.capAdd())) && ((this.capDrop == null) ? (that.capDrop() == null) : this.capDrop.equals(that.capDrop())) && ((this.networkMode == null) ? (that.networkMode() == null) : this.networkMode.equals(that.networkMode())) && ((this.securityOpt == null) ? (that.securityOpt() == null) : this.securityOpt.equals(that.securityOpt())) && ((this.devices == null) ? (that.devices() == null) : this.devices.equals(that.devices())) && ((this.memory == null) ? (that.memory() == null) : this.memory.equals(that.memory())) && ((this.memorySwap == null) ? (that.memorySwap() == null) : this.memorySwap.equals(that.memorySwap())) && ((this.kernelMemory == null) ? (that.kernelMemory() == null) : this.kernelMemory.equals(that.kernelMemory())) && ((this.memorySwappiness == null) ? (that.memorySwappiness() == null) : this.memorySwappiness.equals(that.memorySwappiness())) && ((this.memoryReservation == null) ? (that.memoryReservation() == null) : this.memoryReservation.equals(that.memoryReservation()))
private void startContainer(final String name) throws DockerException, InterruptedException { docker.pull(BUSYBOX); final HostConfig hostConfig = HostConfig.builder().build(); final ContainerConfig config = ContainerConfig.builder() .image(BUSYBOX) .cmd(IDLE_COMMAND) .hostConfig(hostConfig) .build(); final ContainerCreation creation = docker.createContainer(config, name); final String containerId = creation.id(); docker.startContainer(containerId); } }
public HostConfig build() { final HostConfig hostConfig = autoBuild(); validateExtraHosts(hostConfig.extraHosts()); return hostConfig; } }
Builder(HostConfig source) { this.binds = source.binds(); this.blkioWeight = source.blkioWeight(); this.blkioWeightDevice = source.blkioWeightDevice(); this.blkioDeviceReadBps = source.blkioDeviceReadBps(); this.blkioDeviceWriteBps = source.blkioDeviceWriteBps(); this.blkioDeviceReadIOps = source.blkioDeviceReadIOps(); this.blkioDeviceWriteIOps = source.blkioDeviceWriteIOps(); this.containerIdFile = source.containerIdFile(); this.lxcConf = source.lxcConf(); this.privileged = source.privileged(); this.portBindings = source.portBindings(); this.links = source.links(); this.publishAllPorts = source.publishAllPorts(); this.dns = source.dns(); this.dnsOptions = source.dnsOptions(); this.dnsSearch = source.dnsSearch(); this.extraHosts = source.extraHosts(); this.volumesFrom = source.volumesFrom(); this.capAdd = source.capAdd(); this.capDrop = source.capDrop(); this.networkMode = source.networkMode(); this.securityOpt = source.securityOpt(); this.devices = source.devices(); this.memory = source.memory(); this.memorySwap = source.memorySwap(); this.memorySwappiness = source.memorySwappiness(); this.memoryReservation = source.memoryReservation(); this.nanoCpus = source.nanoCpus(); this.cpuPeriod = source.cpuPeriod();
final HostConfig.Builder builder = HostConfig.builder() .binds(binds()) .portBindings(portBindings())
return ((this.binds == null) ? (that.binds() == null) : this.binds.equals(that.binds())) && ((this.blkioWeight == null) ? (that.blkioWeight() == null) : this.blkioWeight.equals(that.blkioWeight())) && ((this.blkioWeightDevice == null) ? (that.blkioWeightDevice() == null) : this.blkioWeightDevice.equals(that.blkioWeightDevice())) && ((this.blkioDeviceReadBps == null) ? (that.blkioDeviceReadBps() == null) : this.blkioDeviceReadBps.equals(that.blkioDeviceReadBps())) && ((this.blkioDeviceWriteBps == null) ? (that.blkioDeviceWriteBps() == null) : this.blkioDeviceWriteBps.equals(that.blkioDeviceWriteBps())) && ((this.blkioDeviceReadIOps == null) ? (that.blkioDeviceReadIOps() == null) : this.blkioDeviceReadIOps.equals(that.blkioDeviceReadIOps())) && ((this.blkioDeviceWriteIOps == null) ? (that.blkioDeviceWriteIOps() == null) : this.blkioDeviceWriteIOps.equals(that.blkioDeviceWriteIOps())) && ((this.containerIdFile == null) ? (that.containerIdFile() == null) : this.containerIdFile.equals(that.containerIdFile())) && ((this.lxcConf == null) ? (that.lxcConf() == null) : this.lxcConf.equals(that.lxcConf())) && ((this.privileged == null) ? (that.privileged() == null) : this.privileged.equals(that.privileged())) && ((this.portBindings == null) ? (that.portBindings() == null) : this.portBindings.equals(that.portBindings())) && ((this.links == null) ? (that.links() == null) : this.links.equals(that.links())) && ((this.publishAllPorts == null) ? (that.publishAllPorts() == null) : this.publishAllPorts.equals(that.publishAllPorts())) && ((this.dns == null) ? (that.dns() == null) : this.dns.equals(that.dns())) && ((this.dnsOptions == null) ? (that.dnsOptions() == null) : this.dnsOptions.equals(that.dnsOptions())) && ((this.dnsSearch == null) ? (that.dnsSearch() == null) : this.dnsSearch.equals(that.dnsSearch())) && ((this.extraHosts == null) ? (that.extraHosts() == null) : this.extraHosts.equals(that.extraHosts())) && ((this.volumesFrom == null) ? (that.volumesFrom() == null) : this.volumesFrom.equals(that.volumesFrom())) && ((this.capAdd == null) ? (that.capAdd() == null) : this.capAdd.equals(that.capAdd())) && ((this.capDrop == null) ? (that.capDrop() == null) : this.capDrop.equals(that.capDrop())) && ((this.networkMode == null) ? (that.networkMode() == null) : this.networkMode.equals(that.networkMode())) && ((this.securityOpt == null) ? (that.securityOpt() == null) : this.securityOpt.equals(that.securityOpt())) && ((this.devices == null) ? (that.devices() == null) : this.devices.equals(that.devices())) && ((this.memory == null) ? (that.memory() == null) : this.memory.equals(that.memory())) && ((this.memorySwap == null) ? (that.memorySwap() == null) : this.memorySwap.equals(that.memorySwap())) && ((this.memorySwappiness == null) ? (that.memorySwappiness() == null) : this.memorySwappiness.equals(that.memorySwappiness())) && ((this.memoryReservation == null) ? (that.memoryReservation() == null) : this.memoryReservation.equals(that.memoryReservation())) && ((this.nanoCpus == null) ? (that.nanoCpus() == null) : this.nanoCpus.equals(that.nanoCpus())) && ((this.cpuPeriod == null) ? (that.cpuPeriod() == null) : this.cpuPeriod.equals(that.cpuPeriod()))
final HostConfig hostConfig = HostConfig.builder() .portBindings(ImmutableMap.of("4711/tcp", singletonList(PortBinding.of("0.0.0.0", probePort))))
private ContainerCreation createContainer() { LOG.debug("Creating Docker container '{}'", containerName); final Map<String, List<PortBinding>> portBindings = new HashMap<>(); for (int dockerPort : ports.keySet()) { List<PortBinding> hostPorts = new ArrayList<>(); hostPorts.add(PortBinding.of("0.0.0.0", ports.get(dockerPort))); portBindings.put(dockerPort + "/tcp", hostPorts); } HostConfig hostConfig = HostConfig.builder() .portBindings(portBindings) .build(); // Create container ContainerConfig config = ContainerConfig.builder() .image(imageName) .hostConfig(hostConfig) .build(); try { ContainerCreation container = dockerClient.createContainer(config, containerName); LOG.debug("Docker container '{}' created", containerName); return container; } catch (DockerException | InterruptedException e) { throw new EnvironmentBuilderException("Unable to create Docker container. Is one already running with the same name?", e); } }
private ContainerConfig buildContainerConfig() { // Bind ports String[] ports = {String.valueOf(params.getPort())}; Map<String, List<PortBinding>> portBindings = new HashMap<>(); for (String port : ports) { List<PortBinding> hostPorts = new ArrayList<>(); hostPorts.add(PortBinding.of(ALL_NETWORK_INTERFACES, port)); portBindings.put(port, hostPorts); } HostConfig hostConfig = HostConfig.builder() .privileged(true) .portBindings(portBindings) .build(); // Compose command line for starting Corfu String cmdLine = new StringBuilder() .append("mkdir -p " + params.getStreamLogDir()) .append(" && ") .append("java -cp *.jar org.corfudb.infrastructure.CorfuServer ") .append(getCommandLineParams()) .toString(); return ContainerConfig.builder() .hostConfig(hostConfig) .image(IMAGE_NAME) .hostname(params.getName()) .exposedPorts(ports) .cmd("sh", "-c", cmdLine) .build(); }
private ContainerCreation createContainer(DockerClient docker) { LOG.debug("Creating Couchbase Docker container '{}'", CONTAINER_NAME); // Bind container ports to host ports final String[] ports = {"8091", "8092", "8093", "8094", "11207", "11210", "11211"}; 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 + "/tcp", hostPorts); } HostConfig hostConfig = HostConfig.builder() .portBindings(portBindings) .build(); // Create container ContainerConfig config = ContainerConfig.builder() .image(COUCHBASE_LATEST_IMAGE_NAME) .hostConfig(hostConfig) .build(); try { ContainerCreation container = docker.createContainer(config, CONTAINER_NAME); LOG.debug("Couchbase Docker container '{}' created", CONTAINER_NAME); return container; } catch (DockerException | InterruptedException e) { throw new EnvironmentBuilderException("Unable to create Couchbase Docker container. Is one already running with the same name?", e); } }
log.info("Starting Docker container {}", imageId); com.spotify.docker.client.messages.HostConfig.Builder hostConfigBuilder = HostConfig .builder(); com.spotify.docker.client.messages.ContainerConfig.Builder containerConfigBuilder = ContainerConfig .builder();
/** * Returns a new {@link HostConfig.Builder} based upon the given configuration. * * Descendant classes can override this method to customize the configuration of the Docker * container's host beyond what is allowed by {@link DockerConfig}. * * @param config * docker container configuration * @return a new {@link HostConfig.Builder} */ protected HostConfig.Builder createHostConfig(final DockerConfig config) { final HostConfig.Builder builder = HostConfig.builder() // .portBindings(createPortBindings(config.getPorts())); for (final HostConfigurer configurer : config.getHostConfigurer()) { configurer.configureHost(builder); } return builder; }