Skip to content
This repository has been archived by the owner on Nov 6, 2018. It is now read-only.

Cannot retrieve logs #79

Open
chamilad opened this issue Feb 21, 2017 · 0 comments
Open

Cannot retrieve logs #79

chamilad opened this issue Feb 21, 2017 · 0 comments

Comments

@chamilad
Copy link
Contributor

chamilad commented Feb 21, 2017

I'm trying to retrieve the logs of a container which starts, executes a program which outputs to stdout, and stops. Following is the code snippet I'm using. However, I'm getting a null as the result of logHandler.getOutput(), and a NPE at line 17. However, when queried through the Docker API manually, I can get all the logs of the executed container. Appreciate any help as I'm not sure how I'd retrieve the logs from the container after calling display(), when looking at the sample code.

        ContainerCreateResponse container = client.container().createNew()
                .withName(containerName)
                .withImage(imageName)
                .done();

        try (
                OutputHandle logHandle = client.container().
                        withName(container.getId())
                        .logs()
                        .writingOutput(System.out)
                        .writingError(System.err)
                        .display()
        ) {

            if (client.container().withName(container.getId()).start()) {
                Thread.sleep(5000);
                 // Using Apache Commons IO to get the String.
                String output = IOUtils.toString(logHandle.getOutput(), "UTF-8");
                client.container().withName(container.getId()).remove();
                return output;
            }
        }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant