use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.
the class DefaultDockerClientTest method testContainerVolumeNoCopy.
@Test
public void testContainerVolumeNoCopy() throws Exception {
requireDockerApiVersionAtLeast("1.23", "Creating a container with volumes with nocopy mode");
sut.pull(BUSYBOX_LATEST);
final String aVolumeName = "avolume";
final String aVolumeTo = "/some/path";
final String nocopyVolumeName = "avolume2";
final String nocopyVolumeTo = "/some/other/path";
sut.createVolume(Volume.builder().name(aVolumeName).build());
sut.createVolume(Volume.builder().name(nocopyVolumeName).build());
final HostConfig hostConfig = HostConfig.builder().appendBinds(Bind.from(aVolumeName).to(aVolumeTo).readOnly(true).build()).appendBinds(Bind.from(nocopyVolumeName).to(nocopyVolumeTo).noCopy(true).build()).build();
final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).hostConfig(hostConfig).build();
final String id = sut.createContainer(config, randomName()).id();
final ContainerInfo info = sut.inspectContainer(id);
final List<ContainerMount> mounts = info.mounts();
assertThat(mounts.size(), equalTo(2));
{
final ContainerMount aMount = Iterables.find(mounts, new Predicate<ContainerMount>() {
@Override
public boolean apply(ContainerMount mount) {
return !("nocopy".equals(mount.mode()));
}
}, null);
assertThat("Could not find a mount (without nocopy)", aMount, notNullValue());
assertThat(aMount.mode(), is(equalTo("ro")));
assertThat(aMount.rw(), is(false));
assertThat(aMount.source(), containsString("/" + aVolumeName + "/"));
assertThat(aMount.destination(), is(equalTo(aVolumeTo)));
}
{
final ContainerMount nocopyMount = Iterables.find(mounts, new Predicate<ContainerMount>() {
@Override
public boolean apply(ContainerMount mount) {
return "nocopy".equals(mount.mode());
}
}, null);
assertThat("Could not find mount (with nocopy)", nocopyMount, notNullValue());
assertThat(nocopyMount.mode(), is(equalTo("nocopy")));
assertThat(nocopyMount.rw(), is(true));
assertThat(nocopyMount.source(), containsString("/" + nocopyVolumeName + "/"));
assertThat(nocopyMount.destination(), is(equalTo(nocopyVolumeTo)));
}
}
use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.
the class DefaultDockerClientTest method testVolumesFrom.
@Test
public void testVolumesFrom() throws Exception {
sut.pull(BUSYBOX_LATEST);
final String volumeContainer = randomName();
final String mountContainer = randomName();
final ContainerConfig volumeConfig = ContainerConfig.builder().image(BUSYBOX_LATEST).addVolume("/foo").cmd("touch", "/foo/bar").build();
sut.createContainer(volumeConfig, volumeContainer);
sut.startContainer(volumeContainer);
sut.waitContainer(volumeContainer);
final HostConfig mountHostConfig = HostConfig.builder().volumesFrom(volumeContainer).build();
final ContainerConfig mountConfig = ContainerConfig.builder().image(BUSYBOX_LATEST).hostConfig(mountHostConfig).cmd("ls", "/foo").build();
sut.createContainer(mountConfig, mountContainer);
sut.startContainer(mountContainer);
sut.waitContainer(mountContainer);
final ContainerInfo info = sut.inspectContainer(mountContainer);
assertThat(info.state().running(), is(false));
assertThat(info.state().exitCode(), is(0));
final String logs;
try (LogStream stream = sut.logs(info.id(), stdout(), stderr())) {
logs = stream.readFully();
}
assertThat(logs, containsString("bar"));
}
use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.
the class DefaultDockerClientTest method testRestartContainer.
@Test
public void testRestartContainer() throws Exception {
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();
sut.restartContainer(containerId);
// Should be running with short run time
{
final ContainerInfo containerInfoLatest = sut.inspectContainer(containerId);
assertTrue(containerInfoLatest.state().running());
assertThat(containerInfoLatest.state().pid(), not(equalTo(originalPid)));
}
}
use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.
the class DefaultDockerClientTest method testTmpfs.
@Test
public void testTmpfs() throws Exception {
requireDockerApiVersionAtLeast("1.22", "TmpFs");
// Pull image
sut.pull(BUSYBOX_LATEST);
final ImmutableMap<String, String> tmpfs = ImmutableMap.of("/tmp", "rw,noexec,nosuid,size=50m");
final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).hostConfig(HostConfig.builder().tmpfs(tmpfs).build()).build();
final ContainerCreation container = sut.createContainer(config, randomName());
final ContainerInfo info = sut.inspectContainer(container.id());
assertThat(info.hostConfig().tmpfs(), is(tmpfs));
}
use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.
the class DefaultDockerClientTest method testMacAddress.
@Test
public void testMacAddress() throws Exception {
requireDockerApiVersionAtLeast("1.18", "Mac Address");
sut.pull(MEMCACHED_LATEST);
final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).cmd("sleep", "1000").macAddress("12:34:56:78:9a:bc").build();
final ContainerCreation container = sut.createContainer(config, randomName());
sut.startContainer(container.id());
final ContainerInfo containerInfo = sut.inspectContainer(container.id());
assertThat(containerInfo, notNullValue());
assertThat(containerInfo.config().macAddress(), equalTo("12:34:56:78:9a:bc"));
}
Aggregations