Course contentsShow
← Cloud and Infrastructure
Lesson 1009 of 2,98920. Docker in DepthFree lesson

ENTRYPOINT: Container Executable

Learn ENTRYPOINT instruction for defining container entry point and combining with CMD for flexible execution.

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:

  • ENTRYPOINT alone: The container runs that executable, period.
  • ENTRYPOINT + CMD: CMD provides default arguments to the ENTRYPOINT executable.
  • Runtime arguments: When users run your container with arguments, those replace CMD but still go to ENTRYPOINT.

Example:

FROM ubuntu:22.04
ENTRYPOINT ["echo", "Hello"]
CMD ["World"]
  • Run without arguments: outputs Hello World
  • Run with docker run myimage Universe: outputs Hello Universe (replaces CMD)

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.