CMD vs ENTRYPOINT in Docker: A Comprehensive DevOps Guide

Sharon Sahadevan
3 min readNov 2, 2023

Understanding the core functionalities of Dockerfile commands for efficient container configuration.

As a DevOps engineer venturing into the depths of containerization, grasping the functionalities of CMD and ENTRYPOINT instructions in a Dockerfile is crucial. These commands are pivotal in defining the behavior of a Docker container at runtime. However, despite their apparent similarity, they serve distinct purposes and are used in varied contexts. Let’s decode the nuances that set them apart.

CMD: Setting the Default for Executable Containers

CMD is your go-to Dockerfile instruction when you need to specify a default command to execute as the container boots up.

It’s the default state of your container, offering the command line that gets activated in the absence of ENTRYPOINT

Think of CMD as the gentle suggestion of the Docker world — it tells the container, “Hey, why not run this command at startup?” But like any suggestion, it’s not binding.

You can override it simply by appending command-line arguments after the image name when you run `docker run`.

Here’s a typical example of using CMD:

CMD ["python", "app.py"]

--

--