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.
Andrew Dorokhov