ENTRYPOINT vs CMD in Dockerfile: Differences and Best Practices
Understand the fundamental differences between ENTRYPOINT and CMD directives and how to combine them for flexible container CLIs.
ENTRYPOINT ["node", "server.js"]
CMD ["--port", "3000"]Step-by-Step Execution Guide
ENTRYPOINT ["executable", "param1", "param2"]JSON array syntax does not invoke a shell wrapper, allowing the process to receive SIGTERM signals properly (PID 1).
CMD executable param1 param2Runs command as "/bin/sh -c executable", which prevents signals from reaching your app.
ENTRYPOINT ["python", "main.py"]
CMD ["--serve"]ENTRYPOINT defines the fixed executable, while CMD provides default arguments that users can override at "docker run".
Critical Docker Pitfalls & Precautions
- β’If you override CMD when running "docker run image:tag custom_arg", only CMD is replaced; ENTRYPOINT remains active.
- β’To completely override ENTRYPOINT, use "docker run --entrypoint /bin/sh image:tag".
ENTRYPOINT vs CMD Explained - Frequently Asked Questions
Common questions about container isolation, signal handling, and runtime behavior.
Use ENTRYPOINT ["node", "index.js"] or CMD ["node", "index.js"] in exec form (JSON array). Combining them allows passing default port or config flags.
Related Docker Command Guides
Browse All Docker RecipesOpen an interactive terminal shell session inside a live running Docker container to inspect files, debug processes, or test network connectivity.
Reclaim gigabytes of hard drive space by removing stopped containers, unused networks, dangling images, and build caches.
Instantly stop all active containers and optionally remove them with a single command.
Copy files or directories between a Docker container and your local host file system without creating a volume mount.
Inspect stdout and stderr output from containers with timestamps, tail line limits, and live streaming.
Best practices for copying files into Docker images. Why COPY is almost always preferred over ADD.