我有一个 Redis 项目。当我停止或重新启动 docker compose 项目时,需要超过 10 秒才能停止 Redis Docker 容器(其他容器会在 1 或 2 秒内停止)。与此同时,Redis 容器start几乎是立即的,与其他容器相比需要很多时间才能stop。将
save
设置为空字符串不起作用。
用
save 60 1
或save
它不会生效到时间停止。
与开发机器(Mac M1 Pro 和 Linux Ryzen 3600 PC)上的 node.js 和 Postgres 容器以及具有 2 个内核的“宠物生产”Intel Xeon 虚拟服务器相比,需要大约 10 倍
至少是增加停止容器或重新启动开发时间的方法吗?我经常使用
docker compose up -d --build
,重启Redis需要一些额外的时间
我不关心Redis数据。开发环境重启后删除即可。
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
不处理 SIGTERM 信号的 bash 脚本有问题。
Dockerfile:
ENTRYPOINT ["/app/start-redis.sh"]
旧start-redis.sh:
#!/usr/bin/env bash
redis-server /usr/local/etc/redis/redis.conf
新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