Tomcat,Docker,日志记录和STDOUT? [英] Tomcat, Docker, Logging, and STDOUT?

查看:724
本文介绍了Tomcat,Docker,日志记录和STDOUT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在docker中运行tomcat,但看不到日志.它们被写入tomcat/logs下的各种日志文件中,但是当tomcat在docker容器中运行时,我看不到它们.

I'm running tomcat in docker, but I can't see the logs. They are written to various log files under tomcat/logs, but I can't see them when tomcat is running in a docker container.

这是我的Dockerfile

Here is my Dockerfile

FROM tomcat:7-jre8
COPY target/MYAPP.war /usr/local/tomcat/webapps/MYAPP.war
RUN ["/usr/local/tomcat/bin/catalina.sh", "start"]

这就是我如何制作图片&从中启动容器:

This is how I build image & start container from it:

docker build -t MYAPP .
docker run -it --rm -p 8080:8080 --name MYAPP MYAPP

tomcat部署MYAPP.war之后,我的应用程序创建了日志文件:/var/log/MYAPP.log

My app creates log file: /var/log/MYAPP.log after tomcat deploys MYAPP.war

我应该如何修改Dockerfile以及应该使用哪个命令来运行它("docker run ..."),以便在使用oneliner启动容器MYAPP之后立即使用"docker run -it --rm -p -p 8080:8080 --name MYAPP MYAPP"/var/log/MYAPP.log的内容是否会打印到标准输出?

How should I amend Dockerfile and which command should I use to run it ("docker run ...") so that right after starting the container MYAPP using the oneliner "docker run -it --rm -p 8080:8080 --name MYAPP MYAPP" the contents of /var/log/MYAPP.log would be printed to stdout?

我试图将下面的命令添加到Dockerfile中,但没有帮助.

I tried to add to Dockerfile the command below but it didn't help.

CMD tail -f /usr/local/MYAPP.log

推荐答案

您似乎对RUNCMD之间的区别感到困惑.

You seem to be confused about the different between RUN and CMD.

RUN指令用于在 build 过程中运行命令.它永远不会在容器中执行.当你写...

The RUN directive is used to run commands during the build process. It is never executed in a container. When you write...

RUN ["/usr/local/tomcat/bin/catalina.sh", "start"]

...这意味着在docker build进程中,Docker将启动tomcat,但会立即将其杀死并继续构建您的映像.

...this means that during the docker build process, Docker will start tomcat, but will immediately kill it and continue to build your image.

只有CMDENTRYPOINT指令定义使用docker run引导映像时将运行的命令.因此,您可能想要类似的东西:

Only the CMD and ENTRYPOINT directives define commands that will be run when you boot an image with docker run. So possibly you want something like:

CMD /usr/local/tomcat/bin/catalina.sh start && tail -f /usr/local/MYAPP.log

这篇关于Tomcat,Docker,日志记录和STDOUT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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