Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read files and stdout from a running Docker container

Tags:

docker

logging

go

How would I go about starting an application in my host machine in order to read files and stdout from a running docker container?

Essentially I want to do this:

docker start containerid    ./myapp // This app will *somehow* have access files and stdout generated by the container I just stared.  

How would I go about doing that? To be more specific with where I am trying to go with this; I want to read the logs and stdout of a docker container and have those logs processed somewhere else.

I am also willing to create another docker container which can read files and stdout from another container, but I don't know if that's possible.

like image 601
rexposadas Avatar asked Jul 07 '14 22:07

rexposadas


People also ask

How can you view the output from a running container?

docker logs <container id> will show you all the output of the container run. If you're running it on ECS, you'll probably need to set DOCKER_HOST=tcp://ip:port for the host that ran the container. My container is already stopped. Using the cmd line doing, docker run -d image, it returns me the container id.

What is stdout in docker?

STDOUT is usually a command's normal output, and STDERR is typically used to output error messages. By default, docker logs shows the command's STDOUT and STDERR .

What is stdin and stdout in docker?

In general they are same as what you have mentioned and read in reference links for python. streams for receiving or reading input (stdin) and printing output (stdout). Example input from the keyboard or printing output to unix terminal. one reference here.

How do I access files outside the docker container?

We can do so using Bind Mounts and Volumes. There's not a lot of difference between the two, except Bind Mounts can point to any folder on the host computer, and are not managed by Docker directly. This will map that folder to the logs subfolder in the user's home directory.


1 Answers

The stdout of the process started by the docker container is available through the docker logs $containerid command (use -f to keep it going forever). Another option would be to stream the logs directly through the docker remote API.

For accessing log files (only if you must, consider logging to stdout or other standard solution like syslogd) your only real-time option is to configure a volume (like Marcus Hughes suggests) so the logs are stored outside the container and available for processing from the host or another container.

If you do not need real-time access to the logs, you can export the files (in tar format) with docker export

like image 190
Abel Muiño Avatar answered Sep 28 '22 03:09

Abel Muiño