🐳

Docker Production Mastery

⚙️ ENTRYPOINT vs CMD

Core Concept

ENTRYPOINT: Defines the main executable (fixed)

CMD: Provides default arguments (overridable)

⭐ Golden Rule: ENTRYPOINT = main command | CMD = default parameters

Basic Example

Dockerfile
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y curl

ENTRYPOINT ["curl"]
CMD ["https://example.com"]
bash
# Normal run
docker run myimage
→ Executes: curl https://example.com

# Override CMD
docker run myimage https://google.com
→ Executes: curl https://google.com

Why Both Together?

  • Flexibility: Different environments can use different args
  • K8s/Compose: Override CMD via YAML configuration
  • No Rebuild: Config changes without rebuilding image
✅ Best Practice: Always use exec form (JSON array)
Dockerfile
# ✅ Correct (Exec form)
ENTRYPOINT ["nginx"]
CMD ["-g", "daemon off;"]

# ❌ Avoid (Shell form)
ENTRYPOINT nginx -g "daemon off;"
👨‍💼

Created By

Ritesh Sharma

DevOps Engineer | Cloud Architect

Azure • Terraform • CI/CD • Kubernetes • Cloud Automation