use of io.fabric8.maven.docker.access.ContainerHostConfig in project docker-maven-plugin by fabric8io.
the class RunService method createContainerHostConfig.
ContainerHostConfig createContainerHostConfig(RunImageConfiguration runConfig, PortMapping mappedPorts, File baseDir) throws DockerAccessException {
RestartPolicy restartPolicy = runConfig.getRestartPolicy();
List<String> links = findContainerIdsForLinks(runConfig.getLinks(), runConfig.getNetworkingConfig().isCustomNetwork());
ContainerHostConfig config = new ContainerHostConfig().extraHosts(runConfig.getExtraHosts()).links(links).portBindings(mappedPorts).privileged(runConfig.getPrivileged()).shmSize(runConfig.getShmSize()).dns(runConfig.getDns()).dnsSearch(runConfig.getDnsSearch()).capAdd(runConfig.getCapAdd()).capDrop(runConfig.getCapDrop()).sysctls(runConfig.getSysctls()).securityOpts(runConfig.getSecurityOpts()).memory(runConfig.getMemory()).memorySwap(runConfig.getMemorySwap()).restartPolicy(restartPolicy.getName(), restartPolicy.getRetry()).logConfig(runConfig.getLogConfiguration()).tmpfs(runConfig.getTmpfs()).ulimits(runConfig.getUlimits()).isolation(runConfig.getIsolation()).cpuShares(runConfig.getCpuShares()).cpus(runConfig.getCpus()).cpuSet(runConfig.getCpuSet()).readonlyRootfs(runConfig.getReadOnly()).autoRemove(runConfig.getAutoRemove());
addVolumeConfig(config, runConfig, baseDir);
addNetworkingConfig(config, runConfig);
return config;
}
use of io.fabric8.maven.docker.access.ContainerHostConfig in project docker-maven-plugin by fabric8io.
the class RunService method addVolumeConfig.
private void addVolumeConfig(ContainerHostConfig config, RunImageConfiguration runConfig, File baseDir) throws DockerAccessException {
RunVolumeConfiguration volConfig = runConfig.getVolumeConfiguration();
if (volConfig != null) {
resolveRelativeVolumeBindings(baseDir, volConfig);
config.binds(volConfig.getBind()).volumesFrom(findVolumesFromContainers(volConfig.getFrom()));
}
}
use of io.fabric8.maven.docker.access.ContainerHostConfig in project docker-maven-plugin by fabric8io.
the class ContainerHostConfig method ulimits.
public ContainerHostConfig ulimits(List<UlimitConfig> ulimitsConfig) {
if (ulimitsConfig != null && ulimitsConfig.size() > 0) {
JsonArray ulimits = new JsonArray();
for (UlimitConfig ulimit : ulimitsConfig) {
JsonObject ulimitConfigJson = new JsonObject();
ulimitConfigJson.addProperty("Name", ulimit.getName());
addIfNotNull(ulimitConfigJson, "Hard", ulimit.getHard());
addIfNotNull(ulimitConfigJson, "Soft", ulimit.getSoft());
ulimits.add(ulimitConfigJson);
}
startConfig.add("Ulimits", ulimits);
}
return this;
}
use of io.fabric8.maven.docker.access.ContainerHostConfig in project docker-maven-plugin by fabric8io.
the class ContainerHostConfig method logConfig.
public ContainerHostConfig logConfig(LogConfiguration logConfig) {
if (logConfig != null) {
LogConfiguration.LogDriver logDriver = logConfig.getDriver();
if (logDriver != null) {
JsonObject logConfigJson = new JsonObject();
logConfigJson.addProperty("Type", logDriver.getName());
Map<String, String> opts = logDriver.getOpts();
if (opts != null && opts.size() > 0) {
JsonObject config = new JsonObject();
for (Map.Entry<String, String> logOpt : opts.entrySet()) {
config.addProperty(logOpt.getKey(), logOpt.getValue());
}
logConfigJson.add("Config", config);
}
startConfig.add("LogConfig", logConfigJson);
}
}
return this;
}
use of io.fabric8.maven.docker.access.ContainerHostConfig in project docker-maven-plugin by fabric8io.
the class DockerAccessWinIT method testCreateContainer.
private void testCreateContainer() throws DockerAccessException {
PortMapping portMapping = new PortMapping(Arrays.asList(new String[] { PORT + ":" + PORT }), new Properties());
ContainerHostConfig hostConfig = new ContainerHostConfig().portBindings(portMapping);
ContainerCreateConfig createConfig = new ContainerCreateConfig(IMAGE).command(new Arguments("ping google.com")).hostConfig(hostConfig);
containerId = dockerClient.createContainer(createConfig, CONTAINER_NAME);
assertNotNull(containerId);
String name = dockerClient.getContainer(containerId).getName();
assertEquals(CONTAINER_NAME, name);
}
Aggregations