Which Dockerfile instruction ensures a specific command runs when a container starts?

Prepare for the KCNA Certification Test. Study with flashcards, multiple-choice questions, and detailed explanations to enhance your understanding of Kubernetes Cloud Native concepts. Ace your exam!

Multiple Choice

Which Dockerfile instruction ensures a specific command runs when a container starts?

Explanation:
Defining what runs when a container starts is handled by the ENTRYPOINT instruction. It specifies the executable that becomes the container’s main process (PID 1), so the container reliably starts exactly that program every time. CMD, in contrast, provides default arguments to that program but can be overridden at runtime by passing a different command to the container. RUN runs commands during image build, not when the container starts, and FROM sets the base image and has no impact on startup behavior. In practice, you often pair ENTRYPOINT with CMD to have a fixed program while still giving it default, overridable arguments.

Defining what runs when a container starts is handled by the ENTRYPOINT instruction. It specifies the executable that becomes the container’s main process (PID 1), so the container reliably starts exactly that program every time. CMD, in contrast, provides default arguments to that program but can be overridden at runtime by passing a different command to the container. RUN runs commands during image build, not when the container starts, and FROM sets the base image and has no impact on startup behavior. In practice, you often pair ENTRYPOINT with CMD to have a fixed program while still giving it default, overridable arguments.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy