312-97 practice question 26 of 35

(Richard Branson has been working as a DevSecOps engineer in an IT company since the past 7 years. He has launched an application in a container one month ago. Recently, he modified the container and would like to commit the changes to a new image. Which of the following commands should Branson use to save the current state of the container as a new image?.)

Full set: 100 questions
Answer options
A: container commit.
B: docker push.
C: container push.
D: docker commit. Correct answer
Correct Answer:
D. docker commit.
Explanation

The docker commit command is used to create a new image from a container's changes. When a developer makes modifications inside a running container (e.g., installing software, modifying configuration files), this command captures the state of the container's filesystem and creates a new, persistent image from it. The new image can then be tagged and pushed to a registry. The basic syntax is docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]], which directly addresses the scenario of saving the current state of a modified container as a new image.

Why Incorrect

A. container commit: This is not a valid command. The Docker command-line interface (CLI) requires the docker executable to be specified first (e.g., docker commit).
B. docker push: This command is used to upload an already existing local image to a remote container registry, such as Docker Hub. It does not create a new image.
C. container push: This is not a valid command in the Docker CLI for the same reason that container commit is invalid.

References

1. Docker Official Documentation, docker commit command reference. The documentation explicitly states, "Create a new image from a container’s changes." It provides the syntax and usage examples for this specific purpose. (docs.docker.com/engine/reference/commandline/commit/, Description section).

2. "Docker: Up & Running, 2nd Edition" by Sean P. Kane and Karl Matthias (O'Reilly Media). Chapter 3, "Images," explains the docker commit command as a method to create a new image layer based on the changes made within a running container.

Scroll to Top