This article helped me a lot: https://www.docker.com/blog/docker-best-practices-choosing-between-run-cmd-and-entrypoint/
Regarding your question, you should make the "core" (unchangeable) part of your container's start command in the Dockerfile using the ENTRYPOINT
instruction in exec form:
ENTRYPOINT ["executable", "arg1", "arg2"]
Then, you can provide additional command line arguments in your compose.yaml
using command:
field and they will be appended to your ENTRYPOINT command. To make it more flexible, you can use variables:
command:
- $ARG3
- $ARG4
So, starting your container using docker compose may look like:
ARG3="arg3" ARG4="arg4" docker compose up
which eventually will call executable arg1 arg2 $ARG3 $ARG4