What purpose does using exec in docker entrypoint scripts serve?

前端 未结 3 1106
眼角桃花
眼角桃花 2020-12-23 11:26

For example in the redis official image:

https://github.com/docker-library/redis/blob/master/2.8/docker-entrypoint.sh

#!/bin/bash
set -e

if [ \"$1\"         


        
3条回答
  •  星月不相逢
    2020-12-23 12:06

    As @Peter Lyons says, using exec will replace the parent process, rather than have two processes running.

    This is important in Docker for signals to be proxied correctly. For example, if Redis was started without exec, it will not receive a SIGTERM upon docker stop and will not get a chance to shutdown cleanly. In some cases, this can lead to data loss or zombie processes.

    If you do start child processes (i.e. don't use exec), the parent process becomes responsible for handling and forwarding signals as appropriate. This is one of the reasons it's best to use supervisord or similar when running multiple processes in a container, as it will forward signals appropriately.

提交回复
热议问题