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

Docker LogPath为空排查:Redis容器JSON日志文件无法找到

Troubleshooting Missing JSON Log Files for Redis via docker-compose

Let's break down your issue step by step and work through fixes:

1. Confirm the Log Driver Your Container Is Actually Using

First, let's check if your Redis container is honoring the json-file driver you configured in docker-compose. Run this command:

docker inspect --format='{{.HostConfig.LogConfig.Type}}' docker-compose-redis_redis_1
  • If the output isn't json-file, your logging configuration isn't being applied to the container.
  • If it returns something like journald, Docker is falling back to the default system log driver (a common quirk in older Docker versions when config compatibility issues arise).

2. Double-Check docker-compose.yml Indentation

YAML is strict about indentation—make sure your logging block is properly nested under the Redis service. A misaligned block will be ignored entirely:

services:
  redis:
    image: redis:latest
    logging: 
      # Limit logs to 200MB (4 rotations of 50M each)
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "4"

If logging sits outside the redis service section, it won't apply to your container at all.

3. Test with a Direct Docker Run (Bypass docker-compose)

To rule out compatibility issues between your old Docker engine and newer docker-compose, launch a test Redis container directly with Docker:

docker run -d --name test-redis --log-driver json-file --log-opt max-size=50m --log-opt max-file=4 redis

Then check for the log path:

docker inspect --format='{{.LogPath}}' test-redis
  • If this returns a valid path (e.g., /var/lib/docker/containers/<container-id>/<container-id>-json.log), the problem is definitely a compatibility gap between your outdated Docker engine and docker-compose.
  • If even this test doesn't generate a JSON log file, check your Docker default log driver:
    docker info | grep Logging Driver
    
    If the default is journald, logs are stored in the system journal instead of JSON files. You can view them with:
    journalctl CONTAINER_NAME=docker-compose-redis_redis_1
    

4. Upgrade Your Docker Engine (Most Critical Fix)

Your Docker engine version (1.13.1) is extremely outdated—released in 2017—and has known bugs and compatibility issues with newer docker-compose versions like 1.24.1. Many logging configuration improvements were added in later Docker releases.

Upgrading to a stable LTS version (e.g., 20.10.x) will resolve most of these compatibility problems and ensure your json-file log driver configuration works as expected.

5. Check Log File Permissions

If the docker inspect command returns a LogPath but you can't access the file, remember that /var/lib/docker/containers/ requires root privileges to view. Use sudo to check the file:

sudo ls -l $(docker inspect --format='{{.LogPath}}' docker-compose-redis_redis_1)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:13:19