Search in sources :

Example 1 with LogToStringContainerCallback

use of org.testcontainers.dockerclient.LogToStringContainerCallback in project testcontainers-java by testcontainers.

the class DockerClientFactoryTest method runCommandInsideDockerShouldNotFailIfImageDoesNotExistsLocally.

@Test
public void runCommandInsideDockerShouldNotFailIfImageDoesNotExistsLocally() {
    final DockerClientFactory dockFactory = DockerClientFactory.instance();
    try {
        // remove tiny image, so it will be pulled during next command run
        dockFactory.client().removeImageCmd(TestcontainersConfiguration.getInstance().getTinyImage()).withForce(true).exec();
    } catch (NotFoundException ignored) {
    // Do not fail if it's not pulled yet
    }
    dockFactory.runInsideDocker(cmd -> cmd.withCmd("sh", "-c", "echo 'SUCCESS'"), (client, id) -> client.logContainerCmd(id).withStdOut(true).exec(new LogToStringContainerCallback()).toString());
}
Also used : NotFoundException(com.github.dockerjava.api.exception.NotFoundException) LogToStringContainerCallback(org.testcontainers.dockerclient.LogToStringContainerCallback) Test(org.junit.Test)

Aggregations

NotFoundException (com.github.dockerjava.api.exception.NotFoundException)1 Test (org.junit.Test)1 LogToStringContainerCallback (org.testcontainers.dockerclient.LogToStringContainerCallback)1