Search in sources :

Example 1 with ContainerHostConfig

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;
}
Also used : RestartPolicy(io.fabric8.maven.docker.config.RestartPolicy) ContainerHostConfig(io.fabric8.maven.docker.access.ContainerHostConfig)

Example 2 with ContainerHostConfig

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()));
    }
}
Also used : RunVolumeConfiguration(io.fabric8.maven.docker.config.RunVolumeConfiguration)

Example 3 with ContainerHostConfig

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;
}
Also used : JsonArray(com.google.gson.JsonArray) UlimitConfig(io.fabric8.maven.docker.config.UlimitConfig) JsonObject(com.google.gson.JsonObject)

Example 4 with ContainerHostConfig

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;
}
Also used : JsonObject(com.google.gson.JsonObject) LogConfiguration(io.fabric8.maven.docker.config.LogConfiguration) Map(java.util.Map)

Example 5 with ContainerHostConfig

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);
}
Also used : Arguments(io.fabric8.maven.docker.config.Arguments) ContainerCreateConfig(io.fabric8.maven.docker.access.ContainerCreateConfig) PortMapping(io.fabric8.maven.docker.access.PortMapping) Properties(java.util.Properties) ContainerHostConfig(io.fabric8.maven.docker.access.ContainerHostConfig)

Aggregations

JsonObject (com.google.gson.JsonObject)3 ContainerHostConfig (io.fabric8.maven.docker.access.ContainerHostConfig)3 ContainerCreateConfig (io.fabric8.maven.docker.access.ContainerCreateConfig)2 PortMapping (io.fabric8.maven.docker.access.PortMapping)2 Arguments (io.fabric8.maven.docker.config.Arguments)2 LogConfiguration (io.fabric8.maven.docker.config.LogConfiguration)2 UlimitConfig (io.fabric8.maven.docker.config.UlimitConfig)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 JsonArray (com.google.gson.JsonArray)1 NetworkConfig (io.fabric8.maven.docker.config.NetworkConfig)1 RestartPolicy (io.fabric8.maven.docker.config.RestartPolicy)1 RunVolumeConfiguration (io.fabric8.maven.docker.config.RunVolumeConfiguration)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1