Inside the Dockerfile:


This is the default command to be run by the entrypoint


This is the program to run the given command.

Docker uses a default entrypoint of /bin/sh -c without a default command.
When you call docker run [options] ubuntu bash, bash is the command you're passing in, so your actually running: /bin/sh -c bash.
You could then set a command in the dockerfile with CMD and this will be used by default unless you call a specific command instead when calling docker run.

You can also specify an ENTRYPOINT in your dockerfile which can be usefull if you want to use your container as more of an execuatable and don't need to run any other executable commands inside.

Which to use?

My advice is to use CMD in most places where you're running a command, but you may want to run a different command instead at some other stage, as if you used entrypoint you wouldn't be able to do this so easily.

But use entrypoint when you want to make the container act more like an executable, as a way of prefixing commands you pass to it with another command.

comments powered by Disqus
Want to setup your own server? Digital Ocean offer $100 free for new accounts.
DigitalOcean Referral Badge