You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 CMD uses startup.sh which launches Tomcat in the background, then tails catalina.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 is tail, 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 the logs folder.
  • Permission gaps: The openjdk:6-jre image runs as a non-root user (usually daemon), 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 webapps folder — the chown step above should resolve this, but you can confirm with:
    docker exec -it <container-id> ls -la /usr/local/tomcat/webapps
    

内容的提问来源于stack exchange,提问作者shriyash Lakhe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:42:27