How do ENTRYPOINT and CMD instructions interact?
Experience Level: Senior
Tags: Docker
Answer
Both ENTRYPOINT and CMD instructions define what command gets executed when running a container. There are few rules that describe their co-operation.
- Dockerfile should specify at least one of CMD or ENTRYPOINT commands.
- ENTRYPOINT should be defined when using the container as an executable.
- CMD should be used as a way of defining default arguments for an ENTRYPOINT command or for executing an ad-hoc command in a container.
- CMD will be overridden when running the container with alternative arguments.
Related Docker job interview questions
What is the STOPSIGNAL instruction good for in Docker?
Docker SeniorWhat is the SHELL instruction good for in Docker?
Docker SeniorHow many CMD instructions can be in a Dockerfile?
Docker SeniorWhat is the CMD instruction good for in Docker?
Docker SeniorWhat is the EXPOSE instruction good for in Docker?
Docker Senior