What purpose does using exec in docker entrypoint scripts serve?

m0meni

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" = 'redis-server' ]; then
    chown -R redis .
    exec gosu redis "$@"
fi

exec "$@"

Why not just run the commands as usual without exec preceding them?

Adrian Mouat

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

What does set -e and exec "$@" do for docker entrypoint scripts?

What purpose does upvar serve?

Does virtualenv serve a purpose (in production) when using docker?

Does virtualenv serve a purpose (in production) when using docker?

What is an opaque response, and what purpose does it serve?

What is the purpose of using exec command

What purpose does the colon builtin serve?

What purpose does the complexity of `Except` serve in Haskell?

What is "->" operator called and purpose does it serve?

What purpose does makeEmptyFunction serve in fbjs?

What purpose does the Public folder serve

What purpose does the spread element serve here

What purpose does injecting SVGs serve?

AdMob what purpose does the Publisher ID serve?

What purpose does googles server serve?

What purpose does an .ok file serve in MRTG?

Does docker compose exec <service> <command> ignore the entrypoint?

What is the purpose of using shift in shell scripts?

What is the "IsolatedCommand" registry value? What purpose does it serve?

What purpose does the .gitignore file serve in Symfony 4?

What purpose does [QueryProperty("Name", "name")] serve in a Xamarin Shell app?

What purpose does the brush serve at the exit point of a scanner?

What purpose does the pre-increment operator serve in C?

What purpose does a <script> tag serve inside of a <noscript> tag?

What real purpose does $.noop() serve in jQuery 1.4?

What purpose does this index serve after Get-ChildItem?

What purpose does placing a png inside an svg serve?

What purpose does reassigning a variable to itself via echo serve?

What purpose does callback.bind() serve when returning a promise?