Bad file format reading the append only file – Redis

I am running redis as docker container from official image on my local Windows Docker Desktop. Sometimes when my Machine and Docker Desktop is restarted, redis refuses to start the service with the below error.

Bad file format reading the append only file appendonly.aof.57.incr.aof: make a backup of your AOF file, then use ./redis-check-aof --fix <filename.manifest>

I have kept the appendonly flag as yes when running the server

redis:
    image: redis:5
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 1s
      timeout: 3s
      retries: 30
    restart: "unless-stopped"
    command: ["redis-server", "--appendonly yes"]
    ports:
      - 6379
    volumes:
      - redis-data:/data

To fix this issue we do exactly what is suggested by the error.

The file to fix is resided in the /data directory of the container so the command will look something like this.

docker-compose run --rm redis redis-check-aof --fix /data/appendonlydir/appendonly.aof.57.incr.aof

Note that there is an appendonlydir directory in the file path. Which can be figured out with the simple ls command

docker-compose run --rm redis ls -lha /data
Creating redis_run … done
total 64K
drwxr-xr-x 3 redis redis 4.0K Aug 1 10:09 .
drwxr-xr-x 1 root root 4.0K Aug 1 10:09 ..
drwx------ 2 redis redis 4.0K Jul 29 12:58 appendonlydir
-rw------- 1 redis redis 52K Aug 1 10:09 dump.rdb

I keep getting this error frequently so thought of documenting this in form of a blog post.

Leave a comment