Search code examples
dockerdocker-composeredisnosqlcontainers

Redis container stops for a long time


I have a pet project with Redis. When I stop or restart docker compose project, it takes over 10 seconds to stop Redis Docker container (other containers stops within 1 or 2 seconds). Meanwhile Redis container starts almost immediately, it takes a lot of times compare to other containers to stop. Setting save to empty string does not effect.

With save 60 1 or save it does not take effect to time to stop.

Takes about 10 times more compare to node.js and Postgres containers on dev machines (Mac M1 Pro and Linux Ryzen 3600 PC) and "pet-production" Intel Xeon virtual server with 2 cores.

Is it way to boost stopping container or restart time for developing at least? I often use docker compose up -d --build and it takes some addition time to restart Redis.

I Does't care about Redis data. It can be deleted after restart on development envoronment.

redis.conf:

loglevel notice

# Modules
loadmodule /usr/lib/redis/modules/redisearch.so
loadmodule /usr/lib/redis/modules/rejson.so
loadmodule /usr/lib/redis/modules/redistimeseries.so

port 0
tls-port 6379

tls-cert-file /certs/server.crt
tls-key-file /certs/server.key
tls-ca-cert-file /certs/ca.crt
tls-dh-params-file /certs/redis.dh

maxmemory 256mb

save # was: `save: 60 1` with the same time to stop 

Solution

  • It was a problem with bash script that does not process SIGTERM signal.

    Dockerfile:

    ENTRYPOINT ["/app/start-redis.sh"]
    

    Old start-redis.sh:

    #!/usr/bin/env bash
    
    redis-server /usr/local/etc/redis/redis.conf
    

    New start-redis.sh:

    #!/usr/bin/env bash
    
    # [ Some work... ]
    
    # Define cleanup function
    stop_redis() {
        echo "==========   Stopping Redis server...   =========="
        redis-cli shutdown
        exit 0
    }
    
    # Trap SIGINT and SIGTERM signals and run cleanup function
    trap stop_redis SIGINT
    trap stop_redis SIGTERM
    
    # Start redis
    redis-server /usr/local/etc/redis/redis.conf &
    wait %?redis-server