use of com.spotify.docker.client.messages.HostConfig in project docker-client by spotify.
the class DefaultDockerClientTest method testIpcMode.
@Test
public void testIpcMode() throws Exception {
requireDockerApiVersionAtLeast("1.18", "IpcMode");
final HostConfig hostConfig = HostConfig.builder().ipcMode("host").build();
final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).cmd("sh", "-c", "while :; do sleep 1; done").hostConfig(hostConfig).build();
final ContainerCreation container = sut.createContainer(config, randomName());
final String containerId = container.id();
sut.startContainer(containerId);
final ContainerInfo info = sut.inspectContainer(containerId);
assertThat(info.hostConfig().ipcMode(), is("host"));
}
use of com.spotify.docker.client.messages.HostConfig in project docker-client by spotify.
the class DefaultDockerClientUnitTest method testCapAddAndDrop.
@Test
@SuppressWarnings("unchecked")
public void testCapAddAndDrop() throws Exception {
final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
final HostConfig hostConfig = HostConfig.builder().capAdd(ImmutableList.of("foo", "bar")).capAdd(ImmutableList.of("baz", "qux")).build();
final ContainerConfig containerConfig = ContainerConfig.builder().hostConfig(hostConfig).build();
server.enqueue(new MockResponse());
dockerClient.createContainer(containerConfig);
final RecordedRequest recordedRequest = takeRequestImmediately();
assertThat(recordedRequest.getMethod(), is("POST"));
assertThat(recordedRequest.getPath(), is("/containers/create"));
assertThat(recordedRequest.getHeader("Content-Type"), is("application/json"));
// TODO (mbrown): use hamcrest-jackson for this, once we upgrade to Java 8
final JsonNode requestJson = toJson(recordedRequest.getBody());
final JsonNode capAddNode = requestJson.get("HostConfig").get("CapAdd");
assertThat(capAddNode.isArray(), is(true));
assertThat(childrenTextNodes((ArrayNode) capAddNode), containsInAnyOrder("baz", "qux"));
}
use of com.spotify.docker.client.messages.HostConfig in project docker-client by spotify.
the class DefaultDockerClientUnitTest method testBindBuilderSelinuxLabeling.
@Test
public void testBindBuilderSelinuxLabeling() throws Exception {
final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
final Bind bindNoSelinuxLabel = HostConfig.Bind.builder().from("noselinux").to("noselinux").build();
final Bind bindSharedSelinuxContent = HostConfig.Bind.builder().from("shared").to("shared").selinuxLabeling(true).build();
final Bind bindPrivateSelinuxContent = HostConfig.Bind.builder().from("private").to("private").selinuxLabeling(false).build();
final HostConfig hostConfig = HostConfig.builder().binds(bindNoSelinuxLabel, bindSharedSelinuxContent, bindPrivateSelinuxContent).build();
final ContainerConfig containerConfig = ContainerConfig.builder().hostConfig(hostConfig).build();
server.enqueue(new MockResponse());
dockerClient.createContainer(containerConfig);
final RecordedRequest recordedRequest = takeRequestImmediately();
final JsonNode requestJson = toJson(recordedRequest.getBody());
final JsonNode binds = requestJson.get("HostConfig").get("Binds");
assertThat(binds.isArray(), is(true));
Set<String> bindSet = childrenTextNodes((ArrayNode) binds);
assertThat(bindSet, hasSize(3));
assertThat(bindSet, hasItem(allOf(containsString("noselinux"), not(containsString("z")), not(containsString("Z")))));
assertThat(bindSet, hasItem(allOf(containsString("shared"), containsString("z"))));
assertThat(bindSet, hasItem(allOf(containsString("private"), containsString("Z"))));
}
use of com.spotify.docker.client.messages.HostConfig in project docker-client by spotify.
the class PushPullIT method startAuthedRegistry.
private static String startAuthedRegistry(final DockerClient client) throws Exception {
final Map<String, List<PortBinding>> ports = singletonMap("5000/tcp", Collections.singletonList(PortBinding.of("0.0.0.0", 5000)));
final HostConfig hostConfig = HostConfig.builder().portBindings(ports).binds(ImmutableList.of(Resources.getResource("dockerRegistry/auth").getPath() + ":/auth", Resources.getResource("dockerRegistry/certs").getPath() + ":/certs")).privileged(true).build();
final ContainerConfig containerConfig = ContainerConfig.builder().image(REGISTRY_IMAGE).hostConfig(hostConfig).env(ImmutableList.of("REGISTRY_AUTH=htpasswd", "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm", "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd", "REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt", "REGISTRY_HTTP_TLS_KEY=/certs/domain.key", "REGISTRY_HTTP_SECRET=super-secret")).build();
return startAndAwaitContainer(client, containerConfig, REGISTRY_NAME);
}
use of com.spotify.docker.client.messages.HostConfig in project docker-client by spotify.
the class DefaultDockerClientTest method testContainerWithCpuOptions.
@Test
public void testContainerWithCpuOptions() throws Exception {
requireDockerApiVersionAtLeast("1.18", "Container creation with cpu options");
sut.pull(BUSYBOX_LATEST);
final HostConfig expected = HostConfig.builder().cpuShares(4096L).cpusetCpus("0,1").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.cpuShares(), equalTo(expected.cpuShares()));
assertThat(actual.cpusetCpus(), equalTo(expected.cpusetCpus()));
}
Aggregations