Hint: If image unused, 'docker rmi' shows untagged and deleted [OK]
Common Mistakes:
Assuming image removal works if container uses it
Expecting no output on successful removal
Confusing image ID with container ID
4. You run docker rmi myimage but get the error: Error response from daemon: conflict: unable to delete image (must be forced) - image is being used by running container. What should you do to fix this?
medium
A. Use docker rm myimage to remove the image
B. Run docker rmi myimage again without changes
C. Stop the running container using the image, then run docker rmi myimage again
D. Restart Docker daemon and try again
Solution
Step 1: Understand the error meaning
The error says the image is used by a running container, so Docker won't remove it without force.
Step 2: Stop the container using the image
You must stop or remove the container using the image before removing the image itself.
Final Answer:
Stop the running container using the image, then run docker rmi myimage again -> Option C
Quick Check:
Stop container before removing image [OK]
Hint: Stop containers using image before removal [OK]
Common Mistakes:
Trying to remove image without stopping containers
Using 'docker rm' which removes containers, not images
Restarting Docker daemon unnecessarily
5. You want to remove all Docker images that are not used by any container to free up space. Which command will safely do this?
hard
A. docker image prune -a
B. docker rmi $(docker images -q)
C. docker rmi -f $(docker ps -aq)
D. docker container prune
Solution
Step 1: Understand the goal
You want to remove all unused images, but keep images used by containers.
Step 2: Identify the correct command
docker image prune -a removes all unused images safely without affecting running containers.
Step 3: Analyze other options
docker rmi $(docker images -q) tries to remove all images, including used ones, causing errors. docker rmi -f $(docker ps -aq) is invalid because docker ps -aq lists containers, not images. docker container prune removes stopped containers, not images.
Final Answer:
docker image prune -a -> Option A
Quick Check:
Remove unused images safely = docker image prune -a [OK]
Hint: Use 'docker image prune -a' to clean unused images [OK]
Common Mistakes:
Trying to remove all images forcibly causing errors
Confusing container prune with image prune
Using container IDs instead of image IDs in commands
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.