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);
}
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());
}
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());
}
}
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());
}
}
Aggregations