You are reclaiming space on a host that runs Docker Engine. The task is to delete every stopped container, remove any networks those containers no longer use, delete only dangling images, and erase anonymous volumes that are no longer referenced while preserving all tagged images. You also want Docker to ask for confirmation before anything is removed. Which single command fulfills these requirements?
The docker system prune sub-command is designed to clean up multiple object types in a single operation. By default it removes stopped containers, unused networks, dangling images and build cache, and it always prompts for confirmation unless --force is supplied. Adding the --volumes flag extends the cleanup to anonymous volumes that are not used by any container. Because the command is executed without the -a/--all flag, only dangling (untagged) images are removed; all tagged images remain, even if no container is currently using them.
docker system prune --volumes therefore meets every requirement.
docker system prune -a --volumes would additionally delete all unused images-including tagged images that become unreferenced after the stopped containers are removed-so it is too aggressive.
docker volume prune touches volumes only and leaves containers and images in place.
docker image prune -a removes images but leaves containers and volumes untouched.
For these reasons, the correct choice is the command that uses docker system prune --volumes.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is a dangling image in Docker?
Open an interactive chat with Bash
What does the --volumes flag do in Docker system prune?
Open an interactive chat with Bash
Why should we avoid using the --all (-a) flag during cleanup?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Services and User Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access