What purpose does using exec in docker entrypoint scripts serve?

前端 未结 3 1098
眼角桃花
眼角桃花 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条回答
  •  -上瘾入骨i
    2020-12-23 12:11

    Think of it as an optimization like tail recursion.

    If running another program is the final act of the shell script, there's not much of a need to have the shell run the program in a new process and wait for it. Using exec, the shell process replaces itself with the program.

    In either case, the exit value of the shell script will be identical1. Whatever program originally called the shell script will see an exit value that is equal to the exit value of the exec`ed program (or 127 if the program cannot be found).

    1 modulo corner cases such as a program doing something different depending on the name of its parent.

提交回复
热议问题