How to manage Docker images?

· Category: Docker

Short answer

Docker image management includes listing images with docker images, tagging with docker tag, removing with docker rmi, and cleaning unused images with docker image prune.

Steps

  1. List local images: docker images or docker image ls.
  2. Tag an image for versioning or registry push: docker tag source target.
  3. Remove an image: docker rmi <image>.
  4. Clean up dangling images: docker image prune.

Example

docker images --filter "dangling=true"
docker tag myapp:v1.0 registry.example.com/myapp:v1.0
docker push registry.example.com/myapp:v1.0
docker rmi myapp:v1.0
docker image prune -f

Remove all unused images:

docker system prune -a

Tips

  • Use meaningful tags like semantic versions instead of latest.
  • Periodically prune unused images to reclaim disk space.
  • Use multi-stage builds to avoid accumulating intermediate images.
  • Sign images with Docker Content Trust for security.

Common issues

  • Cannot delete an image if a container still references it; remove the container first.
  • Untagged images appear as <none>:<none> and consume disk space.
  • Pushing to a registry requires authentication via docker login.