Ever wondered why there are two ways to write Docker instructions like CMD and ENTRYPOINT?
They are called shell form and exec form.
Shell form is easy. You just write your command like you usually do in the terminal.
CMD python app.pyExec form is more clunky. Imagine you are splitting the command by whitespace. You put each chunk of the command into quotes and wrap them with brackets:

Because of that, some commands like pipes don't work in exec form.
Meanwhile, basically all commands work in shell form.
Then why does Docker recommend using the exec form?
Because they have one major difference.
When you use exec form, Docker runs your app directly as PID 1.
When you use shell form, Docker runs your app inside a shell, making the shell, not your app, PID 1.

Why does this matter?
Stop signals like SIGTERM can reach your app easily when it runs directly as PID 1.

But if the shell runs as PID 1 instead, stop signals might not be able to reach your app properly.

Meaning your app won't be able to shut down properly and could result in data loss or unfinished tasks.
That's why, whenever possible, always use the exec form.
- Fee from Anime Coders
PS: If you want to stay competitive as a developer by adding Docker to your resume, try Gacha Coders, a Gacha game that teaches you how to code.
