What is a Dockerfile instruction that is used to run commands?

Prepare for the Docker Certified Associate test with our comprehensive quizzes that include key questions and detailed explanations. Ace your certification!

The instruction used to run commands in a Dockerfile is RUN. This instruction is executed at build time and is responsible for executing commands in the shell to install packages or set up the environment within the container image being built. When a Docker image is created, each RUN command creates a new layer in the image that captures the result of the command.

For example, RUN can be used to execute commands like updating package lists or installing software, and these modifications become part of the final image. By using RUN effectively within a Dockerfile, developers can automate the setup of their application's environment, ensuring that all required dependencies and tools are in place when the container is started.

While CMD is also involved in command execution, it is primarily used to specify the default command that should run when the container is started from the image. CMD does not run at build time; rather, it runs at runtime when the container is launched. Thus, RUN is the appropriate choice when it comes to executing commands during the image build process.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy