Visiting KubeCon North America? See us at Booth # 752
Visiting KubeCon North America? See us at Booth # 752
Visiting KubeCon North America? See us at Booth # 752
Visiting KubeCon North America? See us at Booth # 752
Visiting KubeCon North America? See us at Booth # 752
Visiting KubeCon North America? See us at Booth # 752
Visiting KubeCon North America? See us at Booth # 752
Visiting KubeCon North America? See us at Booth # 752

ENTRYPOINT: Definition, Docker Container, Differences, Syntax, CMD’s Works

Author:
Dhanush VM
Reviewed By:
Sanket Modi
Updated on:
November 25, 2025

Contents

    Clear, practical overview of Docker ENTRYPOINT and CMD—Docker entrypoint explained with a focus on how the ENTRYPOINT instruction and CMD instruction in a Dockerfile control what runs and with which defaults. The H2s cover: syntax and forms (exec vs shell), precedence and argument passing, using ENTRYPOINT and CMD together, runtime overrides, Compose/Kubernetes behavior, signal handling and PID 1, debugging and common pitfalls, plus best-practice patterns with minimal wrapper scripts. You’ll identify which combination would be the best solution for reliable startups, predictable arguments, and clean shutdowns.

    What is ENTRYPOINT?

    The ENTRYPOINT in Docker is a key instruction in the Dockerfile that defines the primary command or executable the container will always run when it starts. It establishes the container’s default behavior, ensuring a consistent and predictable startup process. Unlike CMD, which provides default arguments or commands that can be easily overridden, ENTRYPOINT locks in the main process, so the container always launches with that specific executable. This makes it ideal for defining the core purpose of a container, such as running a web server, service, or application.

    What is ENTRYPOINT in a Dockerfile?

    ENTRYPOINT in a Dockerfile is the Dockerfile instruction that specifies the executable a Docker container will always run when the container starts—it sets the container’s default command path at runtime, while allowing command-line arguments to be appended via **docker run**.  

    The following points explain the two syntax forms of ENTRYPOINT and their effects on how a container runs: -

    • Exec form (preferred) — ENTRYPOINT ["executable","arg1"]: starts the target process directly (exec), preserves signals, accepts extra command line arguments after the docker image name as a default argument or override.  
    • Shell form — ENTRYPOINT command param: runs through a shell (/bin/sh -c), enables environment variable expansion but alters signal handling and syntax.  
    • Interaction with CMD — CMD supplies default argument(s) to the ENTRYPOINT executable; you can override the executable at run time with docker run --entrypoint … for a debugging use case or to execute a different run command.  
    • Lifecycle micro-context — set during **docker build -t** … in the dockerfile; enforced at runtime on **docker run**. If only ENTRYPOINT is defined (no cmd), the container still starts; if neither is set, you need to specify a command on the command line.  
    • Best practices — prefer exec form for PID 1 correctness, add minimal defaults via cmd, and use --entrypoint only when you must override temporarily.

    To ensure consistent container startup and secure runtime behavior

    ‍Download Trusted Container Images Free

    How do you write and use ENTRYPOINT correctly in a Dockerfile?

    ENTRYPOINT defines the executable a container always runs when the container starts; it is baked into the image during **docker build -t** … and can inherit or override base image defaults.  

    The following outlines best practices for defining and implementing ENTRYPOINT effectively in a Dockerfile:-

    Syntax

    • Exec form (preferred): ENTRYPOINT ["**executable**","arg1","arg2"] — JSON array, quoted tokens only; safe with spaces and correct signal handling when the container starts.  
    • Shell form: ENTRYPOINT command arg1 arg2 — parsed by /bin/sh -c; convenient for expansion but weaker for signals.

    Placement

    • Define ENTRYPOINT near the end of the Dockerfile, after setup (ENV, WORKDIR, copies) and before CMD so CMD can supply default arguments.  
    • Set during build (*docker build -t** image:tag .); evaluated when the container starts.  

    Quoting and arguments

    • In exec form, quote each argument separately: ["/usr/bin/app","--flag","value with space"].  
    • Avoid mixing shell-style quoting inside JSON; for expansion, use explicit args (e.g., ["sh","-c","exec app \"$VAR\"]).  

    Image defaults and inheritance

    • A base Docker image may set ENTRYPOINT or CMD; the last occurrence in your Dockerfile overrides inherited defaults in the resulting container images. A container image is a read-only template that packages your application, its runtime, and configuration metadata, so every container started from it shares the same ENTRYPOINT and CMD unless you override them at runtime. This default ENTRYPOINT (the entrypoint in Docker images) is what orchestration and platforms inherit unless you explicitly change it, with container orchestration automating how containers are deployed, scaled, and managed across clusters. 
    • With only ENTRYPOINT, a container without CMD still runs; if neither exists, a command must be provided at runtime.  
    • Confirm effective defaults with docker inspection to see what executes when the container starts.  

    What is CMD in a Dockerfile and how does it work?

    CMD in a Dockerfile is the instruction used to specify the default command (or default arguments) the docker container runs at container startup. If ENTRYPOINT is present, CMD provides default arguments passed to the entrypoint; if ENTRYPOINT is absent, CMD specifies the default executable the container is run with.

    The following explains how CMD works in a Dockerfile—its purpose, syntax, and interaction with ENTRYPOINT.  

    • Syntax
      • Exec form (preferred): CMD ["app","arg1"] — unambiguous JSON; safest for commands and arguments.
      • Shell form: CMD app arg1 — executed via /bin/sh -c; use only when shell features are needed.
    • Interaction with ENTRYPOINT
      • ENTRYPOINT defines the main command; CMD supplies default arguments.
      • Example (Python):
        • ENTRYPOINT ["python","-m","myapp"] and CMD ["-port","8080"] → CMD arguments append to ENTRYPOINT at runtime.
      • Without ENTRYPOINT:
        • CMD ["python","app.py"] → CMD defines the full command.
    • Override behavior at runtime
      • You can override CMD arguments: docker run IMAGE --help.
      • To override entrypoint: docker run --entrypoint /bin/sh IMAGE.
      • When entrypoint is overridden, CMD is ignored unless you supply new arguments.
      • Example ab test:
        • Image built with CMD ["ab","-n","10","-c","2"].
        • You can run: docker run IMAGE ab -n 100 → replaces CMD args.
    • Micro-context and best practices
      • Only one CMD per Dockerfile; the last one takes precedence.
      • Use CMD for runtime defaults; use RUN for build-time tasks (e.g., RUN apt-get update).
      • Prefer exec form for predictable behavior and clarity.
      • Use ENTRYPOINT for fixed command launchers, keep CMD for tunable defaults.
      • Python example:
        • ENTRYPOINT ["python","-m","svc"] + CMD ["-workers","2"] → runtime flags can be overridden when running the container.

    ENTRYPOINT Vs CMD: What’s the difference?

    The following table compares ENTRYPOINT and CMD and how they define container startup behavior.  

    Aspect 

    ENTRYPOINT 

    CMD 

    Role 

    Defines the executable the container always runs at startup 

    Provides default arguments (or the default command only if no ENTRYPOINT exists) 

    When both exist 

    Runs as the main process 

    Appended as arguments to ENTRYPOINT 

    Runtime override 

    Change executable with --entrypoint 

    Override by passing args after the image name 

    Form (recommended) 

    Exec form ["bin","arg"] for correct signal handling 

    Exec form ["arg1","arg2"] as defaults to ENTRYPOINT 

    Shell form effect 

    ENTRYPOINT cmd arg via /bin/sh -c; weaker signal fidelity 

    CMD cmd arg via /bin/sh -c; used only when shell features are needed 

    Image inheritance 

    Last ENTRYPOINT in the Dockerfile wins; baked at build 

    Last CMD in the Dockerfile wins; baked at build 

    Build context 

    Set during **docker build -t** repo/app:tag . 

    Set during **docker build -t** repo/app:tag . 

    Typical usage 

    What to run (fixed launcher) 

    How to run by default (tunable flags/args) 

    Example (Python) 

    ENTRYPOINT ["python","-m","svc"] 

    CMD ["--port","8080","--workers","2"]

    How do CMD and ENTRYPOINT work together in Docker?

    In Docker, ENTRYPOINT (the entrypoint instruction) sets the executable the container will always run, while CMD (the cmd instruction) supplies default arguments to that executable; together, they form the command Docker runs when the container is started (using CMD and ENTRYPOINT). For example:

    ENTRYPOINT ["python","-m","svc"] # docker entrypoint

    CMD ["--port","8080","--log-level","info"] # cmd in docker file  

    When you run the container, Docker executes:
    python -m svc --port 8080 --log-level info — here CMD is passed and passed to ENTRYPOINT (entrypoint with cmd). At runtime you can override the CMD by appending args (docker run IMAGE --port 9090), while changing the launcher requires --entrypoint (replacing the executable docker process). Prefer the exec form of ENTRYPOINT to ensure operating system signals reach PID 1 and downstream processes inside the container; avoid shell-form ENTRYPOINT unless you need shell features. Mental model: ENTRYPOINT sets “what to run,” CMD sets “how to run it by default.

    What are practical examples of using CMD and ENTRYPOINT together in a Dockerfile?

    ENTRYPOINT sets out what runs; CMD sets out how it runs by default. Together, they form the final command when the container is started—with CMD providing default arguments that can be overridden at runtime, while ENTRYPOINT remains at the launcher unless you replace it.

    Practical examples of using CMD and ENTRYPOINT together

    Example 1 — Web service with tunable flags (exec form)

    FROM python:3.12-slim

    WORKDIR /app

    COPY. /aApp

    ENTRYPOINT ["python","-m","myapi"]      # **docker entrypoint** (launcher)

    CMD ["--port","8080","--workers","2"]   # **cmd in docker** (defaults **passed to entrypoint**)  

    • docker run IMAGE --port 9090 → override the cmd only; launcher stays fixed.

    Gain full control over your container startup and deployment workflows

    ‍Book a Demo Today!

    What are the practical use cases of ENTRYPOINT?

    ENTRYPOINT in a Dockerfile is used to define the executable that always runs when starting your container; pair it with CMD for tunable defaults—this form of ENTRYPOINT is best to use in production.  

    The following outlines practical scenarios where ENTRYPOINT is most effectively used in Docker containers: -

    • Fixed launcher for services — Use a docker entrypoint to specify the command (the executable docker) that must run every time; keep flags in CMD (cmd and entrypoint instructions).
    • CLI tools with defaults — Set entrypoint in docker to the tool (e.g., curl) and place options in cmd in docker file so args are easily adjusted at runtime.
    • Signal-safe PID 1 — Exec-form ENTRYPOINT ensures clean handling of operating system signals for graceful shutdowns.
    • Light setup wrapper — A minimal docker-entrypoint.sh validates env/config, then execs the app; launcher stays stable while CMD varies.
    • Policy guardrail — Lock the launcher via entrypoint and cmd instructions so operators can change flags but not replace the process.
    • Orchestration consistency — In Compose/Kubernetes, a stable ENTRYPOINT keeps replicas deterministic whenever the image is run. In a Docker Compose file (for example, docker-compose.yml), the entrypoint field controls the entrypoint in Docker Compose, so you can override the image’s entrypoint in docker compose yml without rebuilding the image.  
    • Debug without rebuild — Temporarily swap the launcher using --entrypoint instead of needing to create a docker image again.
    • Boot-managed containers — For services started during system boot, a fixed ENTRYPOINT gives predictable startups and health checks.
    • Security hardening — ENTRYPOINT drops privileges or applies limits before exec’ing the app—docker entrypoint explained for production baselines.  

    What is ENTRYPOINT in Kubernetes?

    In Kubernetes, ENTRYPOINT refers to the executable defined in a container image that runs automatically when the container starts inside a Pod. Kubernetes does not define its own default ENTRYPOINT; instead, it uses the one specified in the container’s Docker image.

    You can override this default ENTRYPOINT in a Pod specification using the command field, which replaces the image’s entrypoint at runtime. The args field in the Pod spec corresponds to Docker’s CMD, supplying default arguments to the entrypoint.

    In short, Kubernetes inherits the container’s ENTRYPOINT from the image and allows you to modify it through the Pod’s command and args settings when deploying workloads.

    Exec form Vs. Shell form: What's the difference?

    The following compares exec form and shell form in Dockerfiles, highlighting their syntax, execution, and signal-handling differences.  

    Aspect 

    Exec form 

    Shell form 

    Syntax 

    JSON array: ["/app/bin","--flag","value"] 

    Single string: app --flag "$VAR" 

    Invocation 

    Runs the executable directly (no shell) 

    Runs via /bin/sh -c 

    Signals / PID 1 

    Proper operating system signals handling 

    Shell may intercept/ignore signals 

    Args parsing 

    Exact argv; no shell expansion/globbing 

    Subject to quoting, expansion, globbing 

    Best use with Dockerfile 

    Preferred for ENTRYPOINT/CMD 

    Use only when shell features are required   

    FAQ’s

    Q1. How do I debug a Docker container’s ENTRYPOINT command?

    Ans: Override ENTRYPOINT at runtime, for example: docker run --entrypoint /bin/sh IMAGE. Open a shell, run the intended command manually, and inspect where it fails without rebuilding the image.

    Q2. Can I use environment variables inside ENTRYPOINT?

    Ans: Yes, in shell form (ENTRYPOINT command $VAR) where the shell expands variables. In exec form (["command","$VAR"]), variables are not expanded, so use sh -c or a wrapper script to handle them.

    Q3. How does ENTRYPOINT affect container exit codes?

    Ans: The ENTRYPOINT process runs as PID 1, so its exit code becomes the container’s exit status. Ensure your wrapper script ends with exec so the main process’s exit code is propagated correctly.

    Q4. How can I ensure my Docker containers run securely with ENTRYPOINT?

    Ans: Use a fixed ENTRYPOINT for predictable startup, and combine it with verified images, least-privilege users, restricted capabilities, and safe runtime settings to harden the container.

    Q5. Is it a good practice to combine ENTRYPOINT with a wrapper script?

    Ans: Yes, for light setup tasks such as checks and directory creation. The script should finish with exec "$@" so signals and exit codes flow to the main process.

    Q6. Can ENTRYPOINT run multiple commands sequentially?

    Ans: Not directly. ENTRYPOINT runs a single executable. For multiple steps, use a wrapper script or shell form that runs setup commands and then exec the main process, preserving proper signal handling.

    Dhanush VM
    Dhanush V M is a seasoned technology leader with over a decade of expertise spanning DevOps, performance engineering, cloud deployments, and solution architecture. As a Solution Architect at CleanStart, he leads key architectural initiatives, drives modern DevOps practices, and delivers customer-centric solutions that strengthen software supply chain security.
    Share