redis: Doesn't save on SIGTERM

According to http://redis.io/topics/signals Redis is supposed to do a save on SIGTERM:

If Redis is configured to persist on disk using RDB files, a synchronous (blocking) save is performed. Since the save is performed in a synchronous way no additional memory is used.

According to http://docs.docker.com/reference/commandline/cli/#stop Docker sends a SIGTERM followed by a SIGKILL after a period (10 second default).

The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL

It seems to receive the SIGTERM and gracefully shutdown but it does so without a save. Subsequent start of the container doesn’t have the data.

$ docker run --name some-redis -d redis
4f9fd01b2ed8be449610c4210831b583c1c1f3db1e5560ed4c3921fee34f318d
$ docker run -it --link some-redis:redis --rm redis sh -c 'echo set foo bar | redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
OK
$ docker run -it --link some-redis:redis --rm redis sh -c 'echo get foo | redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
"bar"
$ docker stop some-redis
some-redis
$ docker logs some-redis  | tail -n6
[1] 25 Jul 15:25:58.611 # Server started, Redis version 2.8.12
[1] 25 Jul 15:25:58.611 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[1] 25 Jul 15:25:58.611 * The server is now ready to accept connections on port 6379
[1 | signal handler] (1406301986) Received SIGTERM, scheduling shutdown...
[1] 25 Jul 15:26:26.770 # User requested shutdown...
[1] 25 Jul 15:26:26.770 # Redis is now ready to exit, bye bye...
$ docker start some-redis 
some-redis
$ docker run -it --link some-redis:redis --rm redis sh -c 'echo get foo | redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
(nil)

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 2
  • Comments: 18 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@ebuildy, I think that if you don’t want persistence then either start redis with an empty save value, or set it via your testing setup (e.g. redis-cli config set save '').

$ # regular run
$ docker run -it --rm --name redi redis
...
^C1:signal-handler (1677110921) Received SIGINT scheduling shutdown...
1:M 23 Feb 2023 00:08:41.487 # User requested shutdown...
1:M 23 Feb 2023 00:08:41.487 * Saving the final RDB snapshot before exiting.
1:M 23 Feb 2023 00:08:41.499 * DB saved on disk
1:M 23 Feb 2023 00:08:41.499 # Redis is now ready to exit, bye bye...
$ docker exec -it redi redis-cli config get save
1) "save"
2) "3600 1 300 100 60 10000"

$ # no save run
$ docker run -it --rm --name redi redis --save
...
1:M 23 Feb 2023 00:08:49.650 * Ready to accept connections
^C1:signal-handler (1677110940) Received SIGINT scheduling shutdown...
1:M 23 Feb 2023 00:09:00.132 # User requested shutdown...
1:M 23 Feb 2023 00:09:00.132 # Redis is now ready to exit, bye bye...
$ .. $ docker exec -it redi redis-cli config get save
1) "save"
2) ""

By default redis is only an “in memory” key/value store. If you change your first run to make redis persistent: docker run --name some-redis -d redis redis-server --appendonly yes, it will work.

We forgot to add this to the documentation on the hub when we added the volume, it should be there in the next day or so.