Search in sources :

Example 21 with ContainerInfo

use of com.spotify.docker.client.messages.ContainerInfo in project shinyproxy by openanalytics.

the class DockerEngineBackend method doStartProxy.

@Override
protected void doStartProxy(DockerContainerProxy proxy) throws Exception {
    if (proxy.getApp().getDockerNetworkConnections() != null) {
        for (String networkConnection : proxy.getApp().getDockerNetworkConnections()) {
            dockerClient.connectToNetwork(proxy.getContainerId(), networkConnection);
        }
    }
    dockerClient.startContainer(proxy.getContainerId());
    ContainerInfo info = dockerClient.inspectContainer(proxy.getContainerId());
    proxy.setName(info.name().substring(1));
}
Also used : ContainerInfo(com.spotify.docker.client.messages.ContainerInfo)

Example 22 with ContainerInfo

use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.

the class DefaultDockerClientTest method testTopProcessesOfContainer.

@Test
public void testTopProcessesOfContainer() 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);
    // Ensure that it's running so we can check the active processes
    {
        final ContainerInfo containerInfo = sut.inspectContainer(containerId);
        assertThat(containerInfo.state().running(), equalTo(true));
    }
    final TopResults topResults = sut.topContainer(containerId, null);
    assertThat(topResults.titles(), not(Matchers.empty()));
    // there could be one or two processes running, depending on if we happen to catch it in
    // between sleeps
    assertThat(topResults.processes(), hasSize(greaterThanOrEqualTo(1)));
    assertThat(topResults.titles(), either(hasItem("CMD")).or(hasItem("COMMAND")));
    final List<String> firstProcessStatus = topResults.processes().get(0);
    assertThat("All processes will run as 'root'", firstProcessStatus, hasItem("root"));
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) ContainerCreation(com.spotify.docker.client.messages.ContainerCreation) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) Long.toHexString(java.lang.Long.toHexString) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) TopResults(com.spotify.docker.client.messages.TopResults) Test(org.junit.Test)

Example 23 with ContainerInfo

use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.

the class DefaultDockerClientTest method testShmSize.

@Test
public void testShmSize() throws Exception {
    requireDockerApiVersionAtLeast("1.22", "ShmSize");
    // Pull image
    sut.pull(BUSYBOX_LATEST);
    final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).hostConfig(HostConfig.builder().shmSize(10000000L).build()).build();
    final ContainerCreation container = sut.createContainer(config, randomName());
    final ContainerInfo info = sut.inspectContainer(container.id());
    assertThat(info.hostConfig().shmSize(), is(10000000L));
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) ContainerCreation(com.spotify.docker.client.messages.ContainerCreation) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) Test(org.junit.Test)

Example 24 with ContainerInfo

use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.

the class DefaultDockerClientTest method testOomScoreAdj.

@Test
public void testOomScoreAdj() throws Exception {
    requireDockerApiVersionAtLeast("1.22", "OomScoreAdj");
    // Pull image
    sut.pull(BUSYBOX_LATEST);
    final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).hostConfig(HostConfig.builder().oomScoreAdj(// Defaults to 0
    500).build()).build();
    final ContainerCreation container = sut.createContainer(config, randomName());
    final ContainerInfo info = sut.inspectContainer(container.id());
    assertThat(info.hostConfig().oomScoreAdj(), is(500));
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) ContainerCreation(com.spotify.docker.client.messages.ContainerCreation) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) Test(org.junit.Test)

Example 25 with ContainerInfo

use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.

the class DefaultDockerClientTest method verifyNoTimeoutContainer.

private void verifyNoTimeoutContainer(final String volumeContainer, final StringBuffer result) throws Exception {
    log.info("Reading has finished, waiting for program to end.");
    sut.waitContainer(volumeContainer);
    final ContainerInfo info = sut.inspectContainer(volumeContainer);
    assertThat(result.toString().contains("Finished"), is(true));
    assertThat(info.state().running(), is(false));
    assertThat(info.state().exitCode(), is(0));
}
Also used : ContainerInfo(com.spotify.docker.client.messages.ContainerInfo)

Aggregations

ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)68 ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)45 Test (org.junit.Test)41 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)35 Matchers.containsString (org.hamcrest.Matchers.containsString)33 Long.toHexString (java.lang.Long.toHexString)31 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)31 DockerException (com.spotify.docker.client.exceptions.DockerException)15 HostConfig (com.spotify.docker.client.messages.HostConfig)15 IOException (java.io.IOException)9 DockerClient (com.spotify.docker.client.DockerClient)8 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)7 DockerRequestException (com.spotify.docker.client.exceptions.DockerRequestException)5 Container (com.spotify.docker.client.messages.Container)5 ImageInfo (com.spotify.docker.client.messages.ImageInfo)5 LogStream (com.spotify.docker.client.LogStream)4 ImageNotFoundException (com.spotify.docker.client.exceptions.ImageNotFoundException)4 AttachedNetwork (com.spotify.docker.client.messages.AttachedNetwork)4 Path (java.nio.file.Path)4 ContainerMount (com.spotify.docker.client.messages.ContainerMount)3