use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.
the class DefaultDockerClientTest method testKillContainerWithSignals.
@Test
public void testKillContainerWithSignals() throws Exception {
requireDockerApiVersionAtLeast("1.18", "killContainerWithSignals");
sut.pull(BUSYBOX_LATEST);
final ContainerConfig containerConfig = ContainerConfig.builder().image(BUSYBOX_LATEST).cmd("sh", "-c", "while :; do sleep 1; done").build();
final String containerName = randomName();
final ContainerCreation containerCreation = sut.createContainer(containerConfig, containerName);
final String containerId = containerCreation.id();
sut.startContainer(containerId);
// Must be running
final ContainerInfo containerInfo = sut.inspectContainer(containerId);
assertThat(containerInfo.state().running(), equalTo(true));
final ContainerInfo tempContainerInfo = sut.inspectContainer(containerId);
final Integer originalPid = tempContainerInfo.state().pid();
// kill with SIGKILL
sut.killContainer(containerId, DockerClient.Signal.SIGKILL);
// Should not be running
final ContainerInfo containerInfoLatest = sut.inspectContainer(containerId);
assertFalse(containerInfoLatest.state().running());
}
use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.
the class DefaultDockerClientTest method testContainerWithAppArmorLogs.
@Test
public void testContainerWithAppArmorLogs() throws Exception {
requireDockerApiVersionAtLeast("1.21", "StopSignal and AppArmorProfile");
sut.pull(BUSYBOX_LATEST);
final boolean privileged = true;
final boolean publishAllPorts = true;
final String dns = "1.2.3.4";
final HostConfig expected = HostConfig.builder().privileged(privileged).publishAllPorts(publishAllPorts).dns(dns).cpuShares(4096L).build();
final String stopSignal = "SIGTERM";
final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).hostConfig(expected).stopSignal(stopSignal).build();
final String name = randomName();
final ContainerCreation creation = sut.createContainer(config, name);
final String id = creation.id();
sut.startContainer(id);
final ContainerInfo inspection = sut.inspectContainer(id);
final HostConfig actual = inspection.hostConfig();
assertThat(actual.privileged(), equalTo(expected.privileged()));
assertThat(actual.publishAllPorts(), equalTo(expected.publishAllPorts()));
assertThat(actual.dns(), equalTo(expected.dns()));
assertThat(actual.cpuShares(), equalTo(expected.cpuShares()));
assertThat(sut.inspectContainer(id).config().stopSignal(), equalTo(config.stopSignal()));
assertThat(inspection.appArmorProfile(), equalTo(""));
assertThat(inspection.execIds(), equalTo(null));
assertThat(inspection.logPath(), containsString(id + "-json.log"));
assertThat(inspection.restartCount(), equalTo(0L));
assertThat(inspection.mounts().isEmpty(), equalTo(true));
// Wait for the container to exit
sut.waitContainer(id);
final List<Container> containers = sut.listContainers(allContainers(), withStatusExited());
Container targetCont = null;
for (final Container container : containers) {
if (container.id().equals(id)) {
targetCont = container;
break;
}
}
assertNotNull(targetCont);
assertThat(targetCont.imageId(), equalTo(inspection.image()));
}
use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.
the class DefaultDockerClientTest method testReadonlyRootfs.
@Test
public void testReadonlyRootfs() throws Exception {
// Pull image
sut.pull(BUSYBOX_LATEST);
final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).hostConfig(HostConfig.builder().readonlyRootfs(// Defaults to -1
true).build()).build();
final ContainerCreation container = sut.createContainer(config, randomName());
final ContainerInfo info = sut.inspectContainer(container.id());
assertThat(info.hostConfig().readonlyRootfs(), is(true));
}
use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.
the class DefaultDockerClientTest method testLogsNoStdErr.
@Test
public void testLogsNoStdErr() throws Exception {
sut.pull(BUSYBOX_LATEST);
final String container = randomName();
final ContainerConfig volumeConfig = ContainerConfig.builder().image(BUSYBOX_LATEST).cmd("sh", "-c", "echo This message goes to stdout && echo This message goes to stderr 1>&2").build();
sut.createContainer(volumeConfig, container);
sut.startContainer(container);
sut.waitContainer(container);
final ContainerInfo info = sut.inspectContainer(container);
assertThat(info.state().running(), is(false));
assertThat(info.state().exitCode(), is(0));
final String logs;
try (LogStream stream = sut.logs(info.id(), stdout(), stderr(false))) {
logs = stream.readFully();
}
assertThat(logs, containsString("This message goes to stdout"));
assertThat(logs, not(containsString("This message goes to stderr")));
}
use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.
the class DefaultDockerClientTest method testUpdateContainer.
@Test
public void testUpdateContainer() throws Exception {
requireDockerApiVersionAtLeast("1.22", "update container");
final String containerName = randomName();
final HostConfig hostConfig = HostConfig.builder().cpuShares(256L).build();
final ContainerConfig config = ContainerConfig.builder().hostConfig(hostConfig).image(BUSYBOX_LATEST).build();
sut.pull(BUSYBOX_LATEST);
final ContainerCreation container = sut.createContainer(config, containerName);
final ContainerInfo containerInfo = sut.inspectContainer(container.id());
assertThat(containerInfo.hostConfig().cpuShares(), is(256L));
final HostConfig newHostConfig = HostConfig.builder().cpuShares(512L).build();
final ContainerUpdate containerUpdate = sut.updateContainer(containerInfo.id(), newHostConfig);
assertThat(containerUpdate.warnings(), is(nullValue()));
final ContainerInfo newContainerInfo = sut.inspectContainer(container.id());
assertThat(newContainerInfo.hostConfig().cpuShares(), is(512L));
}
Aggregations