如何从正在运行的Docker容器读取文件和stdout [英] How to read files and stdout from a running Docker container

查看:1877
本文介绍了如何从正在运行的Docker容器读取文件和stdout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在主机中启动应用程序,以便从正在运行的docker容器中读取文件和stdout?

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

本质上我想这样做:

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

我该怎么做?更具体地说,我正试图去与这个;我想要读取docker容器的日志和stdout,并将这些日志处理在别的地方。

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.

我也愿意创建另一个docker容器,它可以从另一个容器读取文件和标准输出,但我不知道是否可以。

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容器启动的进程的 stdout 可通过 docker logs 命令(使用 f 永远保持它)。另一种选择是直接通过 docker remote API

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

对于访问日志文件(仅当您必须考虑登录到stdout或其他标准解决方案,如syslogd)时,您的唯一实时选项是配置卷(像Marcus Hughes所说的那样),所以日志存储在容器外面,可以从主机或另一个容器处理。

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.

如果你不需要实时访问日志,您可以导出文件(tar格式)与 docker export

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

这篇关于如何从正在运行的Docker容器读取文件和stdout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆