Docker Community Forums

Share and learn in the Docker community.

How can I get output using "docker logs" when I run an interactive container with a TTY?


(Ali Nabavi) #1

I’ve been using a docker image for running an interactive development environment for myself. (When it starts, it clones a repo, checks out a development branch, etc.) Until now, I’ve only used it for interactive sessions. Now I’d like to collect some data from it with a log aggregator, but running docker logs ... on it produces no output. When I remove the -t flag from the docker run then docker logs does produce output.

Is there a way to open a TTY and still have output available at docker logs? If not, I suppose I could redirect STDOUT and STDERR to a docker volume on container creation. Is that the best way to do it?

TIA,
Ali

Update:

Okay, I think I have a better idea of what’s going on. Reading these helped:

When I did docker run -i . . ., without the -t, all of my output did appear in the docker logs output, however I was without the luxury of a real shell with formatting, prompt, etc. Seems like if I’m going to run a useful (for my purposes) interactive container I’ll need to be more explicit about what I’m trying to log, i.e., define what I’m logging and explicitly handle the output by sending it to a file, syslog, etc. I was just hoping to find a way to get docker to capture all STDOUT and STDERR on the container and send it someplace, despite my opening the container with both -t and -i.

Does this sound accurate?

-Ali