use of com.spotify.docker.client.messages.ProcessConfig in project docker-client by spotify.
the class DefaultDockerClientTest method testExecInspect.
@Test
public void testExecInspect() throws Exception {
requireDockerApiVersionAtLeast("1.16", "Exec Inspect");
// CircleCI uses lxc, doesn't support exec - https://circleci.com/docs/docker/#docker-exec
assumeFalse(CIRCLECI);
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);
final List<ExecCreateParam> createParams = newArrayList(ExecCreateParam.attachStdout(), ExecCreateParam.attachStderr(), ExecCreateParam.attachStdin(), ExecCreateParam.tty());
// some functionality in this test depends on API 1.19 (exec user)
final boolean execUserSupported = dockerApiVersionAtLeast("1.19");
if (execUserSupported) {
createParams.add(ExecCreateParam.user("1000"));
}
final ExecCreation execCreation = sut.execCreate(containerId, new String[] { "sh", "-c", "exit 2" }, createParams.toArray(new ExecCreateParam[createParams.size()]));
final String execId = execCreation.id();
log.info("execId = {}", execId);
final ExecState notStarted = sut.execInspect(execId);
assertThat(notStarted.id(), is(execId));
assertThat(notStarted.running(), is(false));
if (dockerApiVersionLessThan("1.22")) {
assertThat(notStarted.exitCode(), is(0));
} else {
assertThat(notStarted.exitCode(), nullValue());
}
assertThat(notStarted.openStdin(), is(true));
assertThat(notStarted.openStderr(), is(true));
assertThat(notStarted.openStdout(), is(true));
try (final LogStream stream = sut.execStart(execId)) {
stream.readFully();
}
final ExecState started = sut.execInspect(execId);
assertThat(started.id(), is(execId));
assertThat(started.running(), is(false));
assertThat(started.exitCode(), is(2));
assertThat(started.openStdin(), is(true));
assertThat(started.openStderr(), is(true));
assertThat(started.openStdout(), is(true));
final ProcessConfig processConfig = started.processConfig();
assertThat(processConfig.privileged(), is(false));
if (execUserSupported) {
assertThat(processConfig.user(), is("1000"));
}
assertThat(processConfig.tty(), is(true));
assertThat(processConfig.entrypoint(), is("sh"));
assertThat(processConfig.arguments(), Matchers.<List<String>>is(ImmutableList.of("-c", "exit 2")));
if (dockerApiVersionLessThan("1.22")) {
final ContainerInfo containerInfo = started.container();
assertThat(containerInfo.path(), is("sh"));
assertThat(containerInfo.args(), Matchers.<List<String>>is(ImmutableList.of("-c", "while :; do sleep 1; done")));
assertThat(containerInfo.config().image(), is(BUSYBOX_LATEST));
} else {
assertNotNull(started.containerId(), "containerId");
}
}
use of com.spotify.docker.client.messages.ProcessConfig in project docker-client by spotify.
the class DefaultDockerClientTest method testExecInspectNoUser.
@Test
public void testExecInspectNoUser() throws Exception {
requireDockerApiVersionAtLeast("1.16", "Exec Inspect");
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);
final List<ExecCreateParam> createParams = newArrayList(ExecCreateParam.attachStdout(), ExecCreateParam.attachStderr(), ExecCreateParam.attachStdin(), ExecCreateParam.tty());
final ExecCreation execCreation = sut.execCreate(containerId, new String[] { "sh", "-c", "exit 2" }, createParams.toArray(new ExecCreateParam[createParams.size()]));
final String execId = execCreation.id();
log.info("execId = {}", execId);
try (final LogStream stream = sut.execStart(execId)) {
stream.readFully();
}
final ExecState state = sut.execInspect(execId);
assertThat(state.id(), is(execId));
final ProcessConfig processConfig = state.processConfig();
assertThat(processConfig.user(), isEmptyOrNullString());
}
Aggregations