arrow_back
Back

Dockerfile ENTRYPOINT: fixed container entry command

Andrew Dorokhov Andrew Dorokhov schedule 1 min read

ENTRYPOINT configures the executable that runs when the container starts. Unlike CMD, it cannot be fully overridden by docker run arguments — those are passed as arguments to the entrypoint.

Example:

ENTRYPOINT ["/usr/games/cowsay"]

For more complex behavior, use a wrapper script. Create entrypoint.sh:

#!/bin/bash
if [ $# -eq 0 ]; then
    /usr/games/fortune | /usr/games/cowsay
else
    /usr/games/cowsay "$@"
fi

Make it executable (chmod +x entrypoint.sh) and reference it in the Dockerfile:

FROM debian
RUN apt-get update && apt-get install -y cowsay fortune
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]

ENTRYPOINT is often used in startup scripts that initialize environment and services before handling arguments from CMD or docker run.

code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Dockerfile COPY: copying files from the build context

arrow_forward