Docker Redis container orderly shutdown

I am running redis-server in a Docker container on Ubuntu 14.10 x64. If I access the redis database via phpRedisAdmin, do a few edits and then get them to be saved to disk, shutdown the container and then restart it everything is fine – the edited redis keys are present and correct. However, if I edit keys and then shut down the container then restart it the edits do not stick.

Clearly, the dump.rdb file is not being saved automatically when the container is shutdown. I imagine that I could fix this by putting in an /etc/init.d script that is symlinked from /etc/rc6.d. However, I am wondering – why does shutting down a redis container not perform an orderly shutdown of the running process(es) in the container? After all, when I reboot my server (both the server & the container run Ubuntu 14.10) I do not have to explicitly commit the redis db changes to disk.

  • Docker on EC2, RUN command in dockerfile not reading environment variable
  • Correct configuration for selenium server (docker)
  • How to allocate percentage of system resources to Docker?
  • How to wget url like this `https://www.apache.org/dyn/closer.cgi?path=/kafka/0.8.2.1/kafka_2.11-0.8.2.1.tgz` on CentOS 7
  • Docker seems to be migrating database on the server instead of migrating on RDS
  • REPOSITORY <none> TAG <none>
  • docker run command change to .yaml file
  • Git push hang in there
  • How to find Kubernetes pod that's handling the request
  • gitlab can not change gitlab url ,i edit config,yml , gitlab.yml
  • How can I run a Docker container in AWS Elastic Beanstalk with non-default run parameters?
  • Mount Host Directory to Wildfly deployment directory
  • One Solution collect form web for “Docker Redis container orderly shutdown”

    The main process in a Docker container will be sent a SIGTERM signal when you run docker stop -t N CONTAINER. The process should then begin to shut itself down cleanly. If after N seconds (10 by default) this still hasn’t happened, Docker will use a SIGKILL signal, which will kill the process without giving it a chance to clean up. The reason you were having problems was probably because you simply weren’t giving Redis long enough to shutdown cleanly.

    It’s important to note that only the main process in the container (PID 1) will be sent signals. This means that the main process must be responsible for shutting down any child processes in the container, or you can end up with zombie processes.

    If you still have problems with redis not doing what you want on shutdown, you could wrap it in a script which acts as PID 1, catches the SIGTERM signal and does whatever tidying up you want (just make sure you do shutdown redis and any other processes you’ve started).

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.