Docker Logs Issue : Logs are not created or displayed in Tomcat's logs folder in docker container Docker Logs Issue : Logs are not created or displayed in Tomcat's logs folder in docker container docker docker

Docker Logs Issue : Logs are not created or displayed in Tomcat's logs folder in docker container


Here are a few things wrong with your dockerfile:You mention that you need java 6, and yet the line FROM java as of this writing is set to use java:8.

You need to replace the FROM line with FROM java:6-jre or as suggested by the official page: FROM openjdk:6-jre if in 2018 you still need java 6, which is dangerous. I would also strongly suggest to use at least FROM tomcat:7 which should be able to run java 6 applets but will include some bug fixes including support for longer Diffie-Hellman primes for HTTPS (if you are serious about your app's security).

Copt tomcat $CATALINA_HOME you either miss-typed the line to SO, or your image should not build at all. It should be COPY tomcat $CATALINA_HOME

Given that you are using the COPY command there is no need to use RUN mkdir -p prior to this, since the COPY command will automatically create all the required folders.

CMD $CATALINA_HOME/bin/startup.sh && tail -f $CATALINA_HOME/logs/catalina.out

First the tail -f part: since you are looking to tail a log file which might be created and recreated during the server's operation instead of following the FD you should be following the path by doing tail -F (capital F)

startup.sh && tail - tail will never start until startup.sh exits. A better approach is to do tail -F $CATALINA_HOME/logs/catalina.out & inside your startup.sh right before you start your tomcat server. That way tail will be running in the background.

Regardless this is a somewhat dangerous approach and you risk zombie processes because bash does not manage its children processes and neither does docker. I would recommend to use supervisord or something similar.

(From https://docs.docker.com/engine/admin/multi-service_container/)

FROM ubuntu:latestRUN apt-get update && apt-get install -y supervisorRUN mkdir -p /var/log/supervisorCOPY supervisord.conf /etc/supervisor/conf.d/supervisord.confCOPY my_first_process my_first_processCOPY my_second_process my_second_processCMD ["/usr/bin/supervisord"]

Note: this dockerfile sample omits a few of the best practices, e.g. removing the apt cache in the same run command as doing the apt-get update.

Personal favorite is the phusion/baseimage, but it is harder to setup since you'll need to install everything including the java into the image.


If with all of these modifications you still have no luck in seeing the console update, then you'll need to also post the contents of your startup.sh file or other tomcat related configurations.

P.S.: it might be a good idea to do RUN mkdir -p $CATALINA_HOME/logs just to make sure that the logs folder exists for tomcat to write to.

P.P.S.: the java base image is actually using openjdk instead of the oracle one. Just thought I'd point it out


You should check tomcat logging settings. The default logging.properties in the JRE specifies a ConsoleHandler that routes logging to System.err. The default conf/logging.properties in Apache Tomcat also adds several FileHandlers that write to files.

Example logging.properties file to be placed in $CATALINA_BASE/conf:

handlers = 1catalina.org.apache.juli.FileHandler, \           2localhost.org.apache.juli.FileHandler, \           3manager.org.apache.juli.FileHandler, \           java.util.logging.ConsoleHandler.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler############################################################# Handler specific properties.# Describes specific configuration info for Handlers.############################################################1catalina.org.apache.juli.FileHandler.level = FINE1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs1catalina.org.apache.juli.FileHandler.prefix = catalina.2localhost.org.apache.juli.FileHandler.level = FINE2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs2localhost.org.apache.juli.FileHandler.prefix = localhost.3manager.org.apache.juli.FileHandler.level = FINE3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs3manager.org.apache.juli.FileHandler.prefix = manager.3manager.org.apache.juli.FileHandler.bufferSize = 16384java.util.logging.ConsoleHandler.level = FINEjava.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter############################################################# Facility specific properties.# Provides extra control for each logger.############################################################org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFOorg.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = \   2localhost.org.apache.juli.FileHandlerorg.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFOorg.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = \   3manager.org.apache.juli.FileHandler# For example, set the org.apache.catalina.util.LifecycleBase logger to log# each component that extends LifecycleBase changing state:#org.apache.catalina.util.LifecycleBase.level = FINE

Example logging.properties for the servlet-examples web application to be placed in WEB-INF/classes inside the web application:

handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler############################################################# Handler specific properties.# Describes specific configuration info for Handlers.############################################################org.apache.juli.FileHandler.level = FINEorg.apache.juli.FileHandler.directory = ${catalina.base}/logsorg.apache.juli.FileHandler.prefix = servlet-examples.java.util.logging.ConsoleHandler.level = FINEjava.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

More info at https://tomcat.apache.org/tomcat-6.0-doc/logging.html


we can not see the logs in Docker container until unless we mount it.

To build the Dockerfile:-

docker build -t tomcat

To run the Dockerfile Image:-

docker run -p 8080:8080 tomcat

To copy the logs of tomcat present in docker container to mounted container :-

Run this cmd to mount the container:

                                                1stpath    :      2ndpathdocker run \\-d \\-p 8085:8085 \\-v  /usr/local/tomcat/logs:/usr/local/tomcat/logs  \tomcat

or simply

docker run \\-d \\-v  /usr/local/tomcat/logs:/usr/local/tomcat/logs  \tomcat

1st:-/usr/local/tomcat/logs: path of root dir: where we want to copy the logs or destination

2nd:- /usr/local/tomcat/logs: path of tomcat/logs folder present in docker container

tomcat:-name of image

need to change the port if it is busy

now the container is get mount

to get the list of container run : docker ps -a

now get the container id of latest created container:

docker exec -it < mycontainer > bash 

then we can see the logs by

    cd /usr/local/tomcat/logs    usr/local/tomcat/logs# less  Log Name Here   

this to Copy any folder in docker container on root:-

docker cp <containerId>:/file/path/within/container /host/path/target