top of page
Search

Docker CMD vs ENTRYPOINT

  • Writer: Emilia
    Emilia
  • 12 minutes ago
  • 1 min read

Let's discuss the differences in really really simple terms. Plain English!


docker cmd vs entrypoint

Imagine you're telling Docker:

“When you start my container, do this thing.”

Docker has two ways for you to tell it what to do when the container starts:


CMD — the default thing to do

Think of CMD like:

"If you don’t tell me what to do, do this by default."

Example:

CMD ["echo", "hello world"]

That means:

“If no one gives you other instructions, just run echo hello world.”

But if someone runs the container like:

docker run my-image echo goodbye

Then it overrides the CMD. It’ll run echo goodbye instead.


ENTRYPOINT — always do this first

Think of ENTRYPOINT like:

"No matter what, always start with this."

Example:

ENTRYPOINT ["echo"]

Then if someone runs:

docker run my-image hello world

It becomes:

echo hello world

Because ENTRYPOINT is always used, and hello world is added to it.


What if you use both?

You can use both together:

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

Now when the container runs, it does:

python app.py

If someone runs:

docker run my-image other_script.py

It becomes:

python other_script.py

So:

  • ENTRYPOINT = the base command.

  • CMD = the default argument, unless something else is given.


Summary

  • CMD: “Do this unless someone tells me to do something else.”

  • ENTRYPOINT: “Always start with this no matter what.”

 
 
 

Comments


bottom of page