The 'volume with name already exists' error occurs when you try to create a Docker volume using a name that's already taken. Either remove the existing volume, use a different name, or reuse the existing one.
The "volume with name already exists" error in Docker occurs when you attempt to create a new volume using `docker volume create` with a name that's already in use by an existing volume. Docker requires all volume names to be unique within a given storage driver. When you run `docker volume create myvolume` and a volume named "myvolume" already exists, Docker returns this error to prevent accidental conflicts or data confusion. Interestingly, Docker's behavior around volume name conflicts has some nuances. If you try to create a volume with the same name using the same driver, Docker often silently reuses the existing volume (returns success). However, if you specify a different driver or conflicting options, Docker will return an explicit error. This inconsistency can be confusing, especially in automated scripts or CI/CD pipelines where you expect consistent behavior.
First, verify the volume exists and inspect its details:
# List all volumes
docker volume ls
# Filter to find the specific volume
docker volume ls --filter name=myvolume
# Inspect the volume for details
docker volume inspect myvolumeThe inspect command shows important details like the driver, mountpoint, creation time, and any labels. This helps you determine if you can safely remove it or if you should reuse it.
Tip: Check the CreatedAt timestamp to understand when the volume was created and whether it might contain data you need.
Based on your inspection, choose one of these approaches:
Option A: Reuse the existing volume
If the existing volume is acceptable (same driver, suitable for your use case), simply skip the create command. Docker will use the existing volume when you mount it:
# This works even if the volume already exists
docker run -v myvolume:/data myimageOption B: Use a different name
Use a unique prefix (like project name) to avoid conflicts:
docker volume create myproject_myvolumeOption C: Remove the existing volume
If you don't need the existing volume, remove it (see next step).
If you've determined the existing volume can be safely removed:
# Remove a specific volume
docker volume rm myvolume
# If the volume is in use, first find and remove dependent containers
docker ps -a --filter volume=myvolume
docker rm <container_id>
docker volume rm myvolumeIf you get a "volume is in use" error, see our guide on [docker-volume-in-use](/errors/docker-volume-in-use) for detailed steps.
After removal, you can create your new volume:
docker volume create myvolumeFor Docker Compose projects, you have two approaches to handle existing volumes:
Option A: Let Compose manage the volume
Compose automatically creates volumes and handles existing ones gracefully:
# docker-compose.yml
services:
app:
image: myimage
volumes:
- myvolume:/data
volumes:
myvolume:
# Compose creates this if it doesn't exist
# Uses existing volume if it doesOption B: Use an external volume
If the volume was created outside Compose (e.g., manually or by another tool), mark it as external:
volumes:
myvolume:
external: trueThis tells Compose not to create the volume and to expect it already exists.
For automated scripts and CI/CD pipelines, add checks to make volume creation idempotent:
# Check if volume exists before creating
if ! docker volume inspect myvolume &>/dev/null; then
docker volume create myvolume
echo "Volume created"
else
echo "Volume already exists, skipping creation"
fiOr use the Docker API behavior where creating an existing volume (with the same driver) succeeds silently:
# This succeeds even if volume exists (same driver)
docker volume create myvolume 2>/dev/null || trueNote: The second approach works because Docker returns success when the volume exists with the same driver configuration.
Prevent conflicts by using consistent naming conventions:
# Include project name
docker volume create myproject_data
# Include environment
docker volume create myapp_prod_database
# Include timestamp for ephemeral volumes
docker volume create "test_data_$(date +%Y%m%d_%H%M%S)"For Docker Compose, the project name is automatically prepended:
# In directory "myproject" with volume "data"
# Creates: myproject_data
docker compose upYou can control the prefix with the -p flag:
docker compose -p customprefix up
# Creates: customprefix_data### Volume Name Conflict Behavior
Docker's behavior when creating a volume with an existing name depends on the driver and options:
| Scenario | Behavior |
|----------|----------|
| Same name, same driver, no new options | Success (reuses existing) |
| Same name, different driver | Error: volume already exists |
| Same name, same driver, different labels | Success (labels NOT updated) |
This is documented in [GitHub Issue #27345](https://github.com/moby/moby/issues/27345) where users reported that docker volume create doesn't return an error when the volume exists, but also doesn't update labels.
### Volume Naming in Docker Swarm
In Docker Swarm mode, volume naming becomes more complex:
# Local volumes are node-specific
docker volume create --driver local myvolume
# For shared storage across nodes, use volume plugins
docker volume create --driver rexray/ebs myvolumeEach swarm node maintains its own volume namespace, so a volume named "myvolume" on one node is independent of a volume with the same name on another node. This can cause data inconsistency if you expect shared storage.
### Cleaning Up Orphaned Volumes
Over time, orphaned volumes can accumulate. Clean them up safely:
# Remove all unused volumes (not attached to any container)
docker volume prune
# Preview what would be removed
docker volume ls -qf dangling=true
# Remove volumes matching a pattern (careful!)
docker volume ls -q | grep "^test_" | xargs docker volume rm### Docker Compose V2 vs V1 Differences
Docker Compose V2 (the docker compose command) handles volume conflicts differently than V1 (docker-compose):
- V1: Would sometimes error with "volume already exists but was not created by Docker Compose"
- V2: More gracefully reuses existing volumes with matching names
If you encounter V1-specific errors, consider upgrading to Docker Compose V2 or using the external: true directive.
### Volume Drivers and Plugins
When using volume plugins (like REX-Ray, Portworx, or NFS), the "already exists" error might indicate the volume exists in the external storage system:
# Check if it's a driver-level conflict
docker volume inspect myvolume --format '{{.Driver}}'
# List volumes by driver
docker volume ls --filter driver=localContact your storage administrator or check the external system if the conflict comes from a volume plugin.
dockerfile parse error line 5: unknown instruction: RRUN
How to fix 'unknown instruction' Dockerfile parse error in Docker
Error response from daemon: manifest for nginx:nonexistent not found: manifest unknown: manifest unknown
How to fix 'manifest for image:tag not found' in Docker
Error response from daemon: invalid reference format: repository name must be lowercase
How to fix 'repository name must be lowercase' in Docker
Error response from daemon: No such image
How to fix 'No such image' in Docker
Error response from daemon: Container is not running
How to fix 'Container is not running' when using docker exec