1.

What is the difference between ENTRYPOINT and CMD in Dockerfile?

Answer»

ENTRYPOINT is a definition in Dockerfile that SPECIFIES a command that will always be executed when the container starts. It allows us to configure a command along with its parameters that will run as an executable in a container. Even if we do not specify any ENTRYPOINT, we may inherit it from the BASE image specified using the FROM keyword in your Dockerfile. Most of the official DOCKER base images have an ENTRYPOINT of /bin/sh or /bin/bash.

To override the ENTRYPOINT at runtime, we can use --entrypoint.

Whereas, the main purpose of a CMD is to PROVIDE defaults for an executing container. These defaults can include an executable or for executing an ad-hoc command in a container. It can omit the executable as well, in which case we must specify an ENTRYPOINT INSTRUCTION as well specified with the JSON array format.

The thumb rule is that every Dockerfile should specify at least one of CMD or ENTRYPOINT commands.



Discussion

No Comment Found