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.
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.
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 .
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With