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