0
0
Dockerdevops~20 mins

Removing images in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Image Removal Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of removing a non-existent Docker image
What is the output when you run docker rmi non_existent_image on a system where this image does not exist?
Docker
docker rmi non_existent_image
AUntagged: non_existent_image:latest
BImage removed successfully
CDeleted: sha256:abcdef1234567890
DError response from daemon: No such image: non_existent_image
Attempts:
2 left
💡 Hint
Think about what Docker does if the image name is not found locally.
💻 Command Output
intermediate
2:00remaining
Effect of force removing a Docker image
What happens when you run docker rmi -f image_name if the image is currently used by a running container?
Docker
docker rmi -f image_name
AThe image is removed but the running container continues to run
BThe command hangs until the container is stopped manually
CError: conflict: unable to remove image because it is being used by a running container
DThe image is removed and the running container stops immediately
Attempts:
2 left
💡 Hint
Consider what the force flag does in Docker image removal.
Configuration
advanced
2:00remaining
Docker command to remove all dangling images
Which command correctly removes all dangling (unused) Docker images?
Adocker rmi $(docker images -f "dangling=true" -q)
Bdocker rmi $(docker ps -a -q)
Cdocker rmi --all
Ddocker rmi -a dangling
Attempts:
2 left
💡 Hint
Dangling images are those without tags and not used by any container.
Troubleshoot
advanced
2:00remaining
Reason for failure when removing an image with dependent containers
You try to remove an image with docker rmi image_name but get the error: conflict: unable to remove repository reference "image_name" (must force) - container 123abc is using its referenced image. What is the cause?
AThe image name is misspelled and does not exist
BThere is a running or stopped container using the image, preventing removal without force
CDocker daemon is not running, so the command fails
DThe image is corrupted and cannot be removed
Attempts:
2 left
💡 Hint
Think about what Docker protects when containers depend on images.
Best Practice
expert
3:00remaining
Best practice to safely remove unused Docker images in a CI/CD pipeline
In a CI/CD pipeline, which approach is safest to remove unused Docker images without affecting running containers or builds?
AManually remove images by name after stopping all containers
BRun <code>docker rmi -f $(docker images -q)</code> to force remove all images
CRun <code>docker image prune -a --filter "until=24h"</code> to remove images unused for over 24 hours
DDelete the Docker image storage directory on the host filesystem
Attempts:
2 left
💡 Hint
Consider automated cleanup that avoids disrupting running containers.