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
- Improve redis-basics-persistent by actually checking On SIGTERM a dump.rdb should be created when no special parameters are passed. see docker-library/redis#4 — committed to TimWolla/official-images by TimWolla 8 years ago
- Improve redis-basics-persistent by actually checking On SIGTERM a dump.rdb should be created when no special parameters are passed. see docker-library/redis#4 — committed to TimWolla/official-images by TimWolla 8 years ago
- Improve redis-basics-persistent by actually checking On SIGTERM a dump.rdb should be created when no special parameters are passed. see docker-library/redis#4 — committed to TimWolla/official-images by TimWolla 8 years ago
- Improve redis-basics-persistent by actually checking On SIGTERM a dump.rdb should be created when no special parameters are passed. see docker-library/redis#4 — committed to TimWolla/official-images by TimWolla 8 years ago
@ebuildy, I think that if you don’t want persistence then either start redis with an empty
savevalue, or set it via your testing setup (e.g.redis-cli config set save '').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.