I got this error quite a lot, so now I do a batch removal of all unused containers at once:
docker container prune
add -f
to force removal without prompt.
To list all unused containers (without removal):
docker container ls -a --filter status=exited --filter status=created
See here more examples how to prune other objects (networks, volumes, etc.).