A few rules applied when using Entrypoint and CMD
- must specify at least 1 of them
- Use CMD to define default executable but its easily overwritable by
docker run imagename overwrite-cmd-here
- Use ENTRYPOINT when you want the user to use the executable defined. Although its still possible to overwrite entrypoint by passing in
--entrypoint
its a bit harder than CMD - To have the ability to combine CMD and ENTRYPOINT, make sure you use the exec format instead of the shell format
To allow user pass in commandline argument during docker run
Dockerfile
FROM alpine:3.10
ENTRYPOINT ["ls"]
Commandline
docker run --rm sample
bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
docker run --rm sample /usr
bin lib local sbin share
Same technique can be use by having a script as entrypoint and pass overwrite cmd as the way to pass argument in for the entrypoint script
References