CMD vs ENTRYPOINT in a Dockerfile?
Options
- They are identical, and either can be used for any purpose
ENTRYPOINTsets the program;CMDgives default arguments you can override (Correct option)CMDruns once at build time;ENTRYPOINTruns every time at startENTRYPOINTis deprecated, so onlyCMDshould be used today
Answer
ENTRYPOINT sets the executable; CMD provides default arguments that are easily overridden at docker run
Why
Both define what runs when the container starts.
ENTRYPOINT is the fixed program (e.g. gunicorn). CMD provides default arguments, which you can replace by adding arguments to docker run image ....
Use the JSON form ["gunicorn", "app:app"] so your app runs as the main process and receives stop signals properly.
Remember
ENTRYPOINT = the program. CMD = its default arguments.