KhueApps
Home/DevOps/How to fix 'Error response from daemon: remove …: volume is in use'

How to fix 'Error response from daemon: remove …: volume is in use'

Last updated: October 06, 2025

What this error means

Docker refuses to remove a volume if any container (running or stopped) references it. You’ll see:

  • Error response from daemon: remove <volume>: volume is in use

Fix it by identifying the referencing containers, stopping and removing them (or detaching the volume), then removing the volume.

Quickstart (most cases)

  • Find containers using a named volume VOL:
VOL=mydata
# Show all containers that reference the volume
docker ps -a --filter volume="$VOL" --format 'ID={{.ID}}\tName={{.Names}}\tStatus={{.Status}}'

# Stop any running ones
docker stop $(docker ps -q --filter volume="$VOL") 2>/dev/null || true

# Remove all containers that reference the volume
docker rm $(docker ps -aq --filter volume="$VOL") 2>/dev/null || true

# Remove the volume
docker volume rm "$VOL"
  • Using Docker Compose (project in current dir):
docker compose down --volumes

Minimal working example (reproduce and fix)

This demonstrates the error and the fix using a named volume.

# Create a volume and a container that uses it
docker volume create demo
docker run -d --name vtest -v demo:/data busybox sleep 300

# Attempt to remove the volume (will error)
docker volume rm demo
# Error: remove demo: volume is in use - [<container-id>]

# Stop and remove the container, then remove the volume
docker stop vtest && docker rm vtest
docker volume rm demo

Step-by-step diagnosis and fixes

  1. Identify whether it’s a named volume or a bind mount
  • Named volume: you used -v name:/path or a Compose volume.
  • Bind mount: you used -v /host/path:/path. The error here applies to named volumes; bind mounts are removed by the host file system, not docker volume rm.
  1. List volumes and pick the target
docker volume ls
# Inspect details (driver, mountpoint, usage refcount)
docker volume inspect <volume>

Note: RefCount > 0 means at least one container references it.

  1. Find containers that reference the volume
# For a named volume
docker ps -a --filter volume=<volume>

# Or search all containers’ mounts for the name
for c in $(docker ps -aq); do echo "$c"; docker inspect -f '{{json .Mounts}}' "$c" | grep -q '"Name":"<volume>"' && echo "  uses <volume>"; done
  1. Stop and remove referencing containers
docker stop $(docker ps -q --filter volume=<volume>) 2>/dev/null || true
docker rm   $(docker ps -aq --filter volume=<volume>) 2>/dev/null || true

If you cannot remove the container, consider copying data out first:

docker run --rm -v <volume>:/v -v "$PWD":/backup busybox sh -c 'cp -a /v/. /backup/volume_backup'
  1. Remove the volume
docker volume rm <volume>
  1. Optional cleanups
  • Remove dangling (unused) volumes:
docker volume prune
  • Remove stopped containers that may hold references:
docker container prune

Using Docker Compose

  • Remove a stack and its named volumes:
docker compose down --volumes --remove-orphans
  • See which volumes Compose created (project “myapp”):
docker volume ls | grep myapp_
  • Recreate containers without removing volumes:
docker compose up -d --no-deps --build

Force removal notes

  • docker volume rm -f <volume> can remove a volume referenced by stopped containers. It will still fail if a running container is using the volume.
  • Prefer stopping/removing containers explicitly so you don’t orphan container configs or lose data unexpectedly.

Common scenarios and fixes

  • You have a running container using the volume
    • Fix: docker stop <cid> && docker rm <cid>, then remove the volume.
  • The referencing containers are paused
    • Fix: docker unpause <cid> && docker stop <cid> && docker rm <cid>.
  • Volume belongs to a Compose project
    • Fix: run docker compose down --volumes from that project directory.
  • A Swarm service is using the volume
    • Fix: docker service rm <svc> or docker stack rm <stack>; wait for tasks to stop; then remove the volume.
  • Multiple containers share the same volume
    • Fix: stop/remove all referencing containers first (use the filter command to find all of them).

Pitfalls

  • docker rm -v only removes anonymous volumes created with the container. Named volumes remain. Don’t assume -v deletes named volumes.
  • Filtering by volume name only catches named volumes. Bind mounts (host paths) won’t appear in docker volume commands.
  • Removing the wrong volume is irreversible. Always verify with docker volume inspect and confirm mount contents before deletion.
  • On large hosts, command substitution like $(docker ps -aq …) can exceed shell arg limits. Prefer xargs:
docker ps -aq --filter volume=<volume> | xargs -r docker rm

Performance notes

  • Listing containers with filters (docker ps -a --filter volume=…) is efficient; Docker does server-side filtering.
  • Pruning many volumes can be I/O heavy. If disk is tight, remove specific volumes first, then prune.
  • To gauge disk impact before pruning, use:
docker system df -v
  • Avoid repeated docker inspect calls in large loops; batch queries where possible or use --format to reduce payload size.

Tiny FAQ

  • How do I see what’s using a volume?
    • docker ps -a --filter volume=<volume> and docker inspect <container> | grep Mounts.
  • Can I delete a volume without deleting containers?
    • Not while a running container uses it. Stop/remove referencing containers first or use docker volume rm -f for stopped ones.
  • Compose says volumes are in use even after down
    • Another project or manually started container may use the same named volume. Search with docker ps -a --filter volume=<volume>.
  • How do I remove all unused volumes safely?
    • docker volume prune and confirm. Review with docker volume ls -f dangling=true before pruning.

Summary

  • Find referencing containers, stop/remove them, then remove the volume. For Compose, prefer docker compose down --volumes. Use force removal sparingly and back up data when in doubt.

Series: Docker

DevOps