Search in sources :

Example 1 with Device

use of com.spotify.docker.client.messages.Device in project docker-client by spotify.

the class DefaultDockerClientTest method testContainerWithHostConfig.

@Test
public void testContainerWithHostConfig() throws Exception {
    requireDockerApiVersionAtLeast("1.18", "Container creation with HostConfig");
    sut.pull(BUSYBOX_LATEST);
    final boolean privileged = true;
    final boolean publishAllPorts = true;
    final String dns = "1.2.3.4";
    final List<Ulimit> ulimits = newArrayList(Ulimit.builder().name("nofile").soft(1024L).hard(2048L).build());
    final Device expectedDevice = Device.builder().pathOnHost(".").pathInContainer("/foo").cgroupPermissions("mrw").build();
    final HostConfig.Builder hostConfigBuilder = HostConfig.builder().privileged(privileged).publishAllPorts(publishAllPorts).dns(dns).dnsSearch("domain1", "domain2").devices(expectedDevice).ulimits(ulimits);
    if (dockerApiVersionAtLeast("1.21")) {
        hostConfigBuilder.dnsOptions("some", "options");
    }
    final HostConfig expected = hostConfigBuilder.build();
    final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).hostConfig(expected).build();
    final String name = randomName();
    final ContainerCreation creation = sut.createContainer(config, name);
    final String id = creation.id();
    sut.startContainer(id);
    final HostConfig actual = sut.inspectContainer(id).hostConfig();
    assertThat(actual.privileged(), equalTo(expected.privileged()));
    assertThat(actual.publishAllPorts(), equalTo(expected.publishAllPorts()));
    assertThat(actual.dns(), equalTo(expected.dns()));
    if (dockerApiVersionAtLeast("1.21")) {
        assertThat(actual.dnsOptions(), equalTo(expected.dnsOptions()));
    }
    assertThat(actual.dnsSearch(), equalTo(expected.dnsSearch()));
    assertEquals(ulimits, actual.ulimits());
    assertThat(actual.devices(), contains(expectedDevice));
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) ContainerCreation(com.spotify.docker.client.messages.ContainerCreation) Device(com.spotify.docker.client.messages.Device) HostConfig(com.spotify.docker.client.messages.HostConfig) Ulimit(com.spotify.docker.client.messages.HostConfig.Ulimit) Long.toHexString(java.lang.Long.toHexString) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)1 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)1 Device (com.spotify.docker.client.messages.Device)1 HostConfig (com.spotify.docker.client.messages.HostConfig)1 Ulimit (com.spotify.docker.client.messages.HostConfig.Ulimit)1 Long.toHexString (java.lang.Long.toHexString)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)1 Test (org.junit.Test)1