Docker LogPath为空排查:Redis容器JSON日志文件无法找到
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:
If the default isdocker info | grep Logging Driverjournald, 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

