ENTRYPOINT: This instruction configures a container that will run as an executable. It defines the main command that will always be executed when the container starts. It's designed to make the container behave like a single executable.
CMD: This instruction provides default arguments for the ENTRYPOINT command or specifies a command by itself if ENTRYPOINT is not used. It can be overridden by providing arguments to docker run
.

> Running docker run <image>
will execute echo "Hello, World!"
.
> Running docker run <image> "Goodbye!"
will execute echo "Goodbye!"
.
ENTRYPOINT
allows you to turn a container into a self-contained executable. This is particularly useful for command-line tools or applications that perform a specific task.
Imagine you have a container that runs a web server.
ENTRYPOINT
could be the web server's executable (e.g., /usr/sbin/nginx
).
CMD
could be the default configuration file to use (e.g., ["-c", "/etc/nginx/default.conf"]
).
This way, the web server always starts, but users can provide a different configuration file if needed by overriding the CMD
.