/** * Set any custom settings for the create command such as shared memory size. */ private HostConfig buildHostConfig() { HostConfig config = new HostConfig(); if (shmSize != null) { config.withShmSize(shmSize); } if (tmpFsMapping != null) { config.withTmpFs(tmpFsMapping); } return config; }
/** * @return the port bindings */ default List<String> getPortBindings() { List<String> portBindings = new ArrayList<>(); final Ports hostPortBindings = this.getContainerInfo().getHostConfig().getPortBindings(); for (Map.Entry<ExposedPort, Ports.Binding[]> binding : hostPortBindings.getBindings().entrySet()) { for (Ports.Binding portBinding : binding.getValue()) { portBindings.add(String.format("%s:%s", portBinding.toString(), binding.getKey())); } } return portBindings; }
if (hostConfig.isUserDefinedNetwork() && hostConfig.getLinks().length > 0) { if (containerNetwork == null) { containerNetwork = new ContainerNetwork(); containerNetwork.withLinks(hostConfig.getLinks()); .withEndpointsConfig(singletonMap(hostConfig.getNetworkMode(), containerNetwork));
HostConfig hostConfig = new HostConfig() .withCpuPeriod(this.containerCpuPeriod) .withCpuQuota(this.containerCpuQuota) .withMemory(this.containerMemory) .withPortBindings(ports); hostConfig.withBinds(binds);
private CreateContainerCmd createCreateContainerCmd() { List<Bind> volumeBinds = volumeBindSpecs.stream().map(Bind::parse).collect(Collectors.toList()); final HostConfig hostConfig = new HostConfig(); .withCpuShares(cr.cpuShares()) .withMemory(cr.memoryBytes()) .withMemorySwap(cr.memoryBytes()) .withCpuPeriod(cr.cpuQuota() > 0 ? cr.cpuPeriod() : null) .withCpuQuota(cr.cpuQuota() > 0 ? cr.cpuQuota() : null));
/** * Builds {@link HostConfig} * <p> * There is normally no need to overwrite this method!<br> * If you need to overwrite this method, make sure that all ports are published (necessary for mac)! * * @return configured {@link HostConfig} */ protected HostConfig buildHostConfig() { HostConfig hostConfig = new HostConfig(); hostConfig.withPublishAllPorts(Boolean.TRUE); if (!getTmpDirectories().isEmpty() && OSUtils.isLinux()) { Map<String, String> tmpDirectories = new HashMap<>(); getTmpDirectories().forEach(directory -> tmpDirectories.put(directory, "")); hostConfig.withTmpFs(tmpDirectories); } return hostConfig; }
setVolumes(instance, containerConfig.getVolumes(), hostConfig.getBinds()); setPorts(instance, safeGetExposedPorts(containerConfig), hostConfig.getPortBindings()); setField(instance, FIELD_PRIVILEGED, hostConfig.isPrivileged()); setField(instance, FIELD_PUBLISH_ALL_PORTS, hostConfig.isPublishAllPorts()); setLxcConf(instance, hostConfig.getLxcConf()); setListField(instance, FIELD_DNS, hostConfig.getDns()); setListField(instance, FIELD_DNS_SEARCH, hostConfig.getDnsSearch()); setCapField(instance, FIELD_CAP_ADD, hostConfig.getCapAdd()); setCapField(instance, FIELD_CAP_DROP, hostConfig.getCapDrop()); setRestartPolicy(instance, hostConfig.getRestartPolicy()); setDevices(instance, hostConfig.getDevices()); setMemoryReservation(fromInspect, instance); setField(instance, FIELD_BLKIO_WEIGHT, fromInspect, HOST_CONFIG, "BlkioWeight");
public static HostConfig newHostConfig() { return new HostConfig(); }
@Before public void setup() { HostConfig hostConfig = new HostConfig(); hostConfig.withPortBindings(new Ports()); when(inspectContainerResponse.getHostConfig()).thenReturn(hostConfig); when(inspectContainerCmd.exec()).thenReturn(inspectContainerResponse); when(dockerClient.inspectContainerCmd(anyString())).thenReturn(inspectContainerCmd); when(executor.getDockerClient()).thenReturn(dockerClient); CubeContainer cubeContainer = new CubeContainer(); cubeContainer.setRemoveVolumes(false); cube = injectorInst.get().inject(new DockerCube(ID, cubeContainer, executor)); }
List<Bind> binds = new ArrayList<>(); binds.add(new Bind("//var/run/docker.sock", new Volume("/var/run/docker.sock"))); String ryukContainerId = client.createContainerCmd(ryukImage).withHostConfig(new HostConfig().withAutoRemove(true)).withExposedPorts(new ExposedPort(8080)).withPublishAllPorts(true).withName("testcontainers-ryuk-" + DockerClientFactory.SESSION_ID).withLabels(Collections.singletonMap(DockerClientFactory.TESTCONTAINERS_LABEL, "true")).withBinds(binds).withPrivileged(TestcontainersConfiguration.getInstance().isRyukPrivileged()).exec().getId(); client.startContainerCmd(ryukContainerId).exec(); InspectContainerResponse inspectedContainer = client.inspectContainerCmd(ryukContainerId).exec();
createContainerCmd.getHostConfig().withShmSize(containerConfiguration.getShmSize()); createContainerCmd.getHostConfig().withCpuQuota(containerConfiguration.getCpuQuota());
HostConfig.newHostConfig().withNetworkMode("host").withMemory(memoryLimit); if (volumeBinds != null && !volumeBinds.isEmpty()) { final List<Volume> volumes = new ArrayList<>(volumeBinds.size()); }); createContainerCmd.withVolumes(volumes); hostConfig.withBinds(binds);
@SuppressWarnings("resource") private DockerRabbitMQ(Optional<String> hostNamePrefix, Optional<String> clusterIdentity, Optional<String> erlangCookie, Optional<Network> net) { this.hostNameSuffix = clusterIdentity.orElse(UUID.randomUUID().toString()); this.rabbitHostName = hostName(hostNamePrefix); this.container = new GenericContainer<>(Images.RABBITMQ) .withCreateContainerCmdModifier(cmd -> cmd.withName(this.rabbitHostName)) .withCreateContainerCmdModifier(cmd -> cmd.withHostName(this.rabbitHostName)) .withExposedPorts(DEFAULT_RABBITMQ_PORT, DEFAULT_RABBITMQ_ADMIN_PORT) .waitingFor(waitStrategy()) .withLogConsumer(frame -> LOGGER.debug(frame.getUtf8String())) .withCreateContainerCmdModifier(cmd -> cmd.getHostConfig() .withTmpFs(ImmutableMap.of("/var/lib/rabbitmq/mnesia", "rw,noexec,nosuid,size=100m"))); net.ifPresent(this.container::withNetwork); erlangCookie.ifPresent(cookie -> this.container.withEnv(RABBITMQ_ERLANG_COOKIE, cookie)); this.nodeName = DEFAULT_RABBIT_NODE_NAME_PREFIX + "@" + this.rabbitHostName; this.container.withEnv(RABBITMQ_NODENAME, this.nodeName); }
public ContainerAssert hasNetworkMode(String networkMode) { isNotNull(); if (getHostConfig() != null && !Objects.areEqual(getHostConfig().getNetworkMode(), networkMode)) { failWithMessage("Expected container's networkMode to be %s but was %s", networkMode, getHostConfig().getNetworkMode()); } return this; }
/** * compares if microservice has root host access, then container will have the NetworkMode 'host', * otherwise container has to have ExtraHosts * * @param inspectInfo result of docker inspect command * @param microservice microservice * @return boolean */ private boolean isNetworkModeEqual(InspectContainerResponse inspectInfo, Microservice microservice) { boolean isRootHostAccess = microservice.isRootHostAccess(); HostConfig hostConfig = inspectInfo.getHostConfig(); return (isRootHostAccess && "host".equals(hostConfig.getNetworkMode())) || !isRootHostAccess && (hostConfig.getExtraHosts() != null && hostConfig.getExtraHosts().length > 0); }
public HostConfig withPortBindings(List<PortBinding> portBindings) { checkNotNull(portBindings, "portBindings was not specified"); return withPortBindings(portBindings.toArray(new PortBinding[0])); }
containerConfig.getHostConfig().withShmSize(shmSizeInByte);
public HostConfig withBinds(List<Bind> binds) { checkNotNull(binds, "binds was not specified"); return withBinds(binds.toArray(new Bind[binds.size()])); }
public static HostConfig newHostConfig() { return new HostConfig(); }
createContainerCmd.getHostConfig().withShmSize(containerConfiguration.getShmSize()); createContainerCmd.getHostConfig().withCpuQuota(containerConfiguration.getCpuQuota());