Docker容器中Tomcat日志文件夹无日志生成/显示问题求助
Troubleshooting Tomcat Log Issues in Docker Container
Let's break down what's going wrong here and fix it step by step:
Key Issues Identified
- Background Tomcat + tail limitation: Your current
CMDusesstartup.shwhich launches Tomcat in the background, then tailscatalina.out. If Tomcat isn't writing to this file (due to config or permissions), you won't see updates after initial startup. Worse, if Tomcat crashes, the container keeps running because the main process istail, not Tomcat itself. - Missing log files: The absence of
localhost.log,catalina.log, etc., points to either missing logging configuration in your copied Tomcat directory, or permission blocks preventing Tomcat from writing to thelogsfolder. - Permission gaps: The
openjdk:6-jreimage runs as a non-root user (usuallydaemon), so if your copied Tomcat directory has root-only permissions, Tomcat can't create or write log files.
Fixes to Implement
1. Run Tomcat in Foreground
Replace startup.sh with catalina.sh run — this runs Tomcat in the foreground, streaming all logs directly to the container's stdout/stderr. You can view logs with docker logs without relying on tailing a separate file, and the container will stop if Tomcat crashes.
2. Fix Directory Permissions
Add a step to set proper ownership on the Tomcat directory so the runtime user can write logs and unpack your WAR file.
3. Verify Tomcat Configuration Copy
Make sure your local tomcat directory includes the full conf folder, especially logging.properties — this file controls how Tomcat generates its various log files.
Modified Dockerfile
FROM openjdk:6-jre ENV CATALINA_HOME /usr/local/tomcat ENV PATH $CATALINA_HOME/bin:$PATH # Copy local Tomcat files and set ownership for runtime user COPY tomcat $CATALINA_HOME RUN chown -R daemon:daemon $CATALINA_HOME # Add the WAR file to webapps ADD newui.war $CATALINA_HOME/webapps # Run Tomcat in foreground to stream logs directly CMD ["catalina.sh", "run"] EXPOSE 8080
4. Updated Build & Run Commands
# Build the image docker build -t tomcat . # Run the container (use -d for detached mode, then `docker logs -f <container-id>` to follow logs) docker run -p 8080:8080 tomcat
Additional Checks
- After starting the container, verify log files are being created:
docker exec -it <container-id> ls -la /usr/local/tomcat/logs - If your WAR file isn't unpacking, check permissions on the
webappsfolder — thechownstep above should resolve this, but you can confirm with:docker exec -it <container-id> ls -la /usr/local/tomcat/webapps
内容的提问来源于stack exchange,提问作者shriyash Lakhe
相关产品推荐
相关产品推荐

