Reputation: 71
Docker container can only to daemon mode: I run catalina.sh
to start the tomcat.
But the problem is my log will not appear in catalina.out
.
I can look at `docker logs , but this certainly cannot run in a production environment.
I would like to ask how, in production environment, can I have the Tomcat log stored in the document and without the container stopping?
Upvotes: 7
Views: 15599
Reputation: 55
You can override CMD like this:
CMD bash -c "catalina.sh run | tee -a logs/catalina.out"
This way you can show and store the log output at the same time.
But if you even want to store all errors:
CMD bash -c "catalina.sh run |& tee -a logs/catalina.out"
And store into volume like this:
docker run --rm -it -v /some/place:/usr/local/tomcat/logs yourImage
Upvotes: 0
Reputation: 1673
There are options in this (off topic) question to make the tomcat logs run in the foreground.
But to answer your actual question, the docker logs command is the usual way to get logs from a container. You can also find them on the host as they live in a file.
But the best way is to use an external logging service to collect and aggregate the logs, so you don't have to log in to the production server. Logentries is one example (though it's far from perfect). Splunk is another. The Docker logging drivers docs may help.
Upvotes: 3
Reputation: 213
You need to have one process running in foreground in docker container to have the container running.
I use a hack with all my docker images. Create a script run.sh with the following code
#!/bin/sh
service tomcat start
tail -f /dev/null
Make sure before you run the run.sh file in docker, change the permissions.
Addition to Dockerfile will be
COPY run.sh ./run.sh
RUN chmod 755 ./run.sh
CMD ["./run.sh"]
Upvotes: -1
Reputation: 1324377
If you look at the official tomcat docker image, it runs
CMD ["catalina.sh", "run"]
That is enough to starts tomcat in the foreground, displaying the logs on the console.
But, as you said, that might not populate catalina.out.
CMD service tomcat start && tail -f /var/lib/tomcat/logs/catalina.out
Upvotes: 4