Skip to content

Instantly share code, notes, and snippets.

@innyso
Last active April 11, 2020 12:46
Show Gist options
  • Save innyso/a0859643564321a3787028dec376a8fa to your computer and use it in GitHub Desktop.
Save innyso/a0859643564321a3787028dec376a8fa to your computer and use it in GitHub Desktop.
#docker #cmd #overwrite #entrypoint

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment