Day 11beginnerFeb 11, 2026

ENTRYPOINT vs CMD — Know When to Use Each

Using the wrong instruction means your container either can't be customized or doesn't behave like a proper executable.

dockerdockerfilebest-practices
Share:

What

ENTRYPOINT sets the main executable for a container, making it behave like a binary. CMD provides default arguments that can be overridden at runtime. When used together, ENTRYPOINT defines the command and CMD supplies the default flags or arguments.

Why It Matters

Understanding the difference lets you build containers that are both predictable and flexible. ENTRYPOINT ensures your container always runs the intended process, while CMD lets users customize behavior without modifying the Dockerfile.

Example

# Using CMD alone (easily overridden)
CMD ["python", "app.py"]
# docker run myapp bash  <-- replaces entire command

# Using ENTRYPOINT + CMD together (recommended pattern)
ENTRYPOINT ["python"]
CMD ["app.py"]
# docker run myapp test.py  <-- only overrides CMD

# Real-world example: a CLI tool container
FROM python:3.12-slim
COPY . /app
WORKDIR /app
ENTRYPOINT ["python", "manage.py"]
CMD ["runserver", "0.0.0.0:8000"]
dockerfile

Common Mistake

Using only CMD when the container should always run a specific executable. This lets users accidentally replace the entire command with docker run myapp bash, bypassing your intended entrypoint.

Quick Fix

Use ENTRYPOINT for the executable that must always run, and CMD for the default arguments. Always use the exec form (JSON array) instead of the shell form to avoid signal handling issues.

Key Takeaways

  • 1ENTRYPOINT = the executable (always runs)
  • 2CMD = default arguments (can be overridden)
  • 3Combine both for flexible, predictable containers
  • 4Always use exec form: ["cmd", "arg"]
  • 5docker run myimage newarg overrides CMD only

Was this tip helpful?

Help us improve the DevOpsPath daily collection

Share: