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 Error : no space left on device on windows
  • Docker hub automated build fails but locally not
  • Docker API - Exec start returns “Page not found”
  • Can't connect to (exposed, published) port from host
  • How to test code that works with Docker?
  • Deploy nginx official image, the volumn mount incorrectly
  • Use: docker build -t myapp . cannot get image successfully
  • Docker container published ports not accessible?
  • Forward port from docker bridge to local network?
  • Could not call another container using its name as host in docker-compose
  • example to deploy docker image on kubernetes from java
  • docker commit not saving changes made by java installation
  • 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.