Table of Contents

Docker Entrypoint and CMD

ENTRYPOINT is the command that runs when a container starts. CMD provides default arguments. The Dockerfile CMD is overridden by arguments to docker run. Use ENTRYPOINT for the main command and CMD for common default arguments. Both can be exec form (JSON array) or shell form (string).

# Dockerfile
ENTRYPOINT ["python", "app.py"]
CMD ["--port", "8000"]
 
# At runtime
$ docker run myapp                    # uses default: python app.py --port 8000
$ docker run myapp --port 9000        # override CMD: python app.py --port 9000
$ docker run --entrypoint sh myapp    # override ENTRYPOINT

If you specify only CMD in the Dockerfile, docker run arguments replace it entirely. If you specify ENTRYPOINT, docker run arguments append to it. Exec form (["cmd", "arg"]) avoids shell interpretation; shell form ("cmd arg") runs through /bin/sh -c. Use exec form for consistency and to avoid shell quirks.