nginx), Docker will pull the image if it isn’t already present, then start a container. Example output from docker run nginx (abridged):
- List images that are stored locally with
docker images. Example output:
docker rmi IMAGE— remove one or more images.docker rm CONTAINER— remove one or more containers.
alpine:latest image:
alpine, verify remaining images:
docker rmi will fail with a conflict error:
docker ps and docker ps -a to locate such containers:
docker ps— lists running containersdocker ps -a— lists all containers, including exited/stopped ones
docker ps, docker ps -a, and docker images should show no entries for those containers/images.
Quick command reference
Cleaning up many unused resources
When you have many images and containers while experimenting,
docker system prune is a convenient way to remove unused resources. It prompts for confirmation and removes:
- all stopped containers
- all networks not used by at least one container
- all dangling images (untagged)
- unused build cache
Be careful with
docker system prune. It permanently deletes stopped containers, dangling images, and other unused resources. If you need to preserve any stopped container or image, do not prune.- Inspect containers before removing them to avoid losing important state (use
docker inspect <container>). - If you need to force-remove an image despite references, use
docker rmi -f <image>— but prefer removing or exporting containers first. - For more details, see the official Docker docs: https://docs.docker.com/engine/reference/commandline/cli/