ENTRYPOINT: Container Executable
What you'll learn: How to define the executable that runs when your container starts, and how to combine it with CMD for flexible, predictable behavior.
The Container's "Main Program"
While CMD provides a default command that can be overridden, ENTRYPOINT defines the primary executable your container will always run. Think of it as the container's core purpose: ENTRYPOINT is the program, and CMD supplies default arguments to it.
When you set ENTRYPOINT, you're saying "this container is designed to run this specific executable"—users can still pass arguments, but they can't easily change what program runs.
How ENTRYPOINT and CMD Work Together
Here's where it gets powerful:
ENTRYPOINTalone: The container runs that executable, period.ENTRYPOINT+CMD:CMDprovides default arguments to theENTRYPOINTexecutable.- Runtime arguments: When users run your container with arguments, those replace
CMDbut still go toENTRYPOINT.
Example:
FROM ubuntu:22.04
ENTRYPOINT ["echo", "Hello"]
CMD ["World"]
- Run without arguments: outputs
Hello World - Run with
docker run myimage Universe: outputsHello Universe(replacesCMD)
This pattern lets you build containers that behave like command-line tools with sensible defaults but customizable arguments.
When to Use ENTRYPOINT
Use ENTRYPOINT when your container has a single, well-defined purpose—like a web server, database, or utility tool. Use ENTRYPOINT + CMD when you want default behavior users can easily customize without rewriting the entire command.
Key Takeaway:
ENTRYPOINT defines the container's primary executable, while CMD provides default arguments—together they create flexible, predictable containers that behave like purpose-built tools.