12

I manually deleted a docker managed subvolumes

btrfs subvolume delete /var/lib/docker/btrfs/subvolumes/<subvolume id>

but when I try to recreate it gives me this error that I'm not able to solve without nuclearize the docker installation

Error response from daemon: stat /var/lib/docker/btrfs/subvolumes/<subvolume id>: no such file or directory

already tried to stop/rm -f the container, docker system prune -f and systemctl restart docker.service to no avail

Hio
  • 141
  • 1
  • 6
  • 1
    You usually shouldn't manually modify anything in `/var/lib/docker` at all. If you've corrupted that tree, it usually works to stop the Docker daemon, delete all of `/var/lib/docker` and restart the daemon; you'll have to rebuild/re-pull any images you had locally and recreate containers and named volumes. – David Maze Jan 04 '22 at 11:32
  • 1
    Thank you for clarifying me that. What brought me to delete the subvolumes was an uncorrectable btrfs error as a result of a device scrub. After locating the subvolumes that had the corrupted file in its directory tree I deleted it: there's a way to safely remove the subvolume through docker console? – Hio Jan 04 '22 at 11:58
  • See https://stackoverflow.com/questions/46672001/is-it-safe-to-clean-docker-overlay2/ – BMitch Jan 04 '22 at 12:07

2 Answers2

14

I also ended up with the error after deleting btrfs subvolumes myself (the bug that subvolumes are not freed by docker system prune still exists).

To recover, you have to delete /var/lib/docker as well:

systemctl stop docker
rm -rf /var/lib/docker
systemctl start docker
Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239
  • amazing, i was in a really weird state with a Docker installation on Arch / Manjaro after a timeshift restore. Wiping this fixed it all! – Luke Belbina Mar 28 '23 at 22:44
3

well , i encountered same issue with docker on fedora which uses btrfs by default , Deleting the /var/lib/docker directory would remove all Docker data, including images, containers, volumes, and other configuration files.
Doing so will essentially reset Docker to a clean state, as if you've just installed Docker for the first time.

However, deleting the /var/lib/docker directory will lead to data loss.
All data related to Docker, such as running containers, images, and volumes, will be permanently lost. If you have important data stored within Docker containers or volumes, it will be gone after deleting this directory.
removing images, and only btrfs directory in path /var/lib/docker/btrfs will fix the issue and no need to docker system prune or deleting the hole docker directory

docker rm -f $(docker ps -aq)
docker rmi $(docker images -aq)
sudo systemctl stop docker
sudo rm -rf /var/lib/docker/btrfs
sudo systemctl start docker

this is a much faster and safer fix to this issue
note that deleting btrfs directory may take a while since it may has too many files

Neo Mn
  • 150
  • 1
  • 12