Search in sources :

Example 6 with ContainerHostConfig

use of io.fabric8.maven.docker.access.ContainerHostConfig in project docker-maven-plugin by fabric8io.

the class DockerAccessIT 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)

Example 7 with ContainerHostConfig

use of io.fabric8.maven.docker.access.ContainerHostConfig in project docker-maven-plugin by fabric8io.

the class ContainerHostConfigTest method testLogConfig.

@Test
public void testLogConfig() {
    ContainerHostConfig hc = new ContainerHostConfig();
    Map<String, String> opts = new HashMap<>();
    opts.put("gelf-address", "udp://10.0.0.1:12201");
    opts.put("labels", "label1,label2");
    LogConfiguration logConfig = new LogConfiguration.Builder().logDriverName("gelf").logDriverOpts(opts).build();
    hc.logConfig(logConfig);
    // TODO: Does order matter?
    assertEquals("{\"LogConfig\":{\"Type\":\"gelf\",\"Config\":{\"gelf-address\":\"udp://10.0.0.1:12201\",\"labels\":\"label1,label2\"}}}", hc.toJson());
}
Also used : HashMap(java.util.HashMap) LogConfiguration(io.fabric8.maven.docker.config.LogConfiguration) Test(org.junit.Test)

Example 8 with ContainerHostConfig

use of io.fabric8.maven.docker.access.ContainerHostConfig in project docker-maven-plugin by fabric8io.

the class ContainerHostConfigTest method testUlimits.

@Test
public void testUlimits() throws JSONException {
    Object[] data = { "{Ulimits: [{Name:bla, Hard:2048, Soft: 1024}]}", "bla", 2048, 1024, "{Ulimits: [{Name:bla, Soft: 1024}]}", "bla", null, 1024, "{Ulimits: [{Name:bla, Hard: 2048}]}", "bla", 2048, null, "{Ulimits: [{Name:bla, Hard: 2048}]}", "bla=2048", null, null, "{Ulimits: [{Name:bla, Soft: 1024}]}", "bla=:1024", null, null, "{Ulimits: [{Name:bla, Hard: 2048, Soft: 1024}]}", "bla=2048:1024", null, null, "{Ulimits: [{Name:bla, Hard: 2048}]}", "bla=2048:", null, null };
    for (int i = 0; i < data.length; i += 4) {
        ContainerHostConfig hc = new ContainerHostConfig();
        hc.ulimits(Collections.singletonList(data[1].toString().contains("=") ? new UlimitConfig((String) data[1]) : new UlimitConfig((String) data[1], (Integer) data[2], (Integer) data[3])));
        assertEquals(JsonFactory.newJsonObject((String) data[0]), hc.toJsonObject());
    }
}
Also used : UlimitConfig(io.fabric8.maven.docker.config.UlimitConfig) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Example 9 with ContainerHostConfig

use of io.fabric8.maven.docker.access.ContainerHostConfig in project docker-maven-plugin by fabric8io.

the class RunService method addNetworkingConfig.

private void addNetworkingConfig(ContainerHostConfig config, RunImageConfiguration runConfig) throws DockerAccessException {
    NetworkConfig networkConfig = runConfig.getNetworkingConfig();
    if (networkConfig.isStandardNetwork()) {
        String alias = networkConfig.getContainerAlias();
        String containerId = alias != null ? findContainerId(alias, false) : null;
        config.networkMode(networkConfig.getStandardMode(containerId));
    } else if (networkConfig.isCustomNetwork()) {
        config.networkMode(networkConfig.getCustomNetwork());
    }
}
Also used : NetworkConfig(io.fabric8.maven.docker.config.NetworkConfig)

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