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.
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
My app creates log file: /var/log/MYAPP.log after tomcat deploys MYAPP.war
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?
I tried to add to Dockerfile the command below but it didn't help.
CMD tail -f /usr/local/MYAPP.log
You seem to be confused about the different between RUN
and CMD
.
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"]
...this means that during the docker build
process, Docker will start tomcat, but will immediately kill it and continue to build your image.
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
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