Search in sources :

Example 16 with ContainerInfo

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

the class DefaultDockerClientTest method testLogsSince.

@Test
public void testLogsSince() throws Exception {
    requireDockerApiVersionAtLeast("1.19", "/logs?since=timestamp");
    sut.pull(BUSYBOX_LATEST);
    final String container = randomName();
    final ContainerConfig volumeConfig = ContainerConfig.builder().image(BUSYBOX_LATEST).cmd("echo", "This was printed too late").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;
    // Get logs since the current timestamp. This should return nothing.
    try (LogStream stream = sut.logs(info.id(), stdout(), stderr(), since((int) (System.currentTimeMillis() / 1000L)))) {
        logs = stream.readFully();
    }
    assertThat(logs, not(containsString("This message was printed too late")));
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) 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) Test(org.junit.Test)

Example 17 with ContainerInfo

use of com.spotify.docker.client.messages.ContainerInfo 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"));
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) ContainerCreation(com.spotify.docker.client.messages.ContainerCreation) HostConfig(com.spotify.docker.client.messages.HostConfig) 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) Test(org.junit.Test)

Example 18 with ContainerInfo

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

the class DockerContainerClient method loadMountedFolders.

private void loadMountedFolders(String zaleniumContainerName) {
    if (!this.mntFoldersAndHttpEnvVarsChecked.get()) {
        String containerId = getContainerId(zaleniumContainerName);
        if (containerId == null) {
            return;
        }
        ContainerInfo containerInfo = null;
        try {
            containerInfo = dockerClient.inspectContainer(containerId);
        } catch (DockerException | InterruptedException e) {
            logger.warn(nodeId + " Error while getting mounted folders and env vars.", e);
            ga.trackException(e);
        }
        loadMountedFolders(containerInfo);
    }
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo)

Example 19 with ContainerInfo

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

the class DockerContainerClient method getContainerExtraHosts.

private synchronized List<String> getContainerExtraHosts(String zaleniumContainerName) {
    if (zaleniumExtraHosts != null) {
        return zaleniumExtraHosts;
    }
    String containerId = getContainerId(zaleniumContainerName);
    ContainerInfo containerInfo;
    try {
        containerInfo = dockerClient.inspectContainer(containerId);
        zaleniumExtraHosts = containerInfo.hostConfig().extraHosts();
    } catch (DockerException | InterruptedException e) {
        logger.warn(nodeId + " Error while getting Zalenium extra hosts.", e);
        ga.trackException(e);
    }
    return Optional.ofNullable(zaleniumExtraHosts).orElse(DEFAULT_DOCKER_EXTRA_HOSTS);
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo)

Example 20 with ContainerInfo

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

the class DockerContainerClient method loadIsZaleniumPrivileged.

private void loadIsZaleniumPrivileged(String zaleniumContainerName) {
    if (!this.isZaleniumPrivilegedChecked.getAndSet(true)) {
        String containerId = getContainerId(zaleniumContainerName);
        if (containerId == null) {
            return;
        }
        ContainerInfo containerInfo;
        try {
            containerInfo = dockerClient.inspectContainer(containerId);
            isZaleniumPrivileged = containerInfo.hostConfig().privileged();
        } catch (DockerException | InterruptedException e) {
            logger.warn(nodeId + " Error while getting value to check if Zalenium is running in privileged mode.", e);
            ga.trackException(e);
        }
    }
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) 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