docker / cli

The Docker CLI
Apache License 2.0
4.9k stars 1.92k forks source link

Unable to remove volume with trailing slash in name #4631

Open pcwilcox opened 11 months ago

pcwilcox commented 11 months ago

Description

The CLI fails to remove docker volumes with trailing slashes. I inadvertently created a volume docs/ and now cannot get rid of it. It's not used by any containers but docker volume prune silently fails to remove it, and docker volume rm fails with an error.

$ docker volume ls
DRIVER             VOLUME NAME
glusterfs:latest   docs/
$ docker volume prune -a
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
$ docker volume ls
DRIVER             VOLUME NAME
glusterfs:latest   docs/
$ docker volume rm docs/
Error response from daemon: volume docs not found
$ docker volume rm "docs/"
Error response from daemon: volume docs not found

Reproduce

  1. docker volume create $NAME/
  2. docker volume rm $NAME/

Expected behavior

docker volume rm $NAME should remove the volume.

docker volume prune -a should remove the volume since it isn't in use.

docker version

Client: Docker Engine - Community
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.20.10
 Git commit:        afdd53b
 Built:             Thu Oct 26 09:08:26 2023
 OS/Arch:           linux/arm64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:08:26 2023
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.24
  GitCommit:        61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
 runc:
  Version:          1.1.9
  GitCommit:        v1.1.9-0-gccaecfc
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client: Docker Engine - Community
 Version:    24.0.7
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.21.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 3
  Running: 3
  Paused: 0
  Stopped: 0
 Images: 3
 Server Version: 24.0.7
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: active
  NodeID: uepwih8tcsr3wvimi3t96w7l9
  Is Manager: true
  ClusterID: 858o3kw80bjqsx683euxz92dd
  Managers: 5
  Nodes: 7
  Default Address Pool: 10.0.0.0/8
  SubnetSize: 24
  Data Path Port: 4789
  Orchestration:
   Task History Retention Limit: 5
  Raft:
   Snapshot Interval: 10000
   Number of Old Snapshots to Retain: 0
   Heartbeat Tick: 1
   Election Tick: 10
  Dispatcher:
   Heartbeat Period: 5 seconds
  CA Configuration:
   Expiry Duration: 3 months
   Force Rotate: 0
  Autolock Managers: false
  Root Rotation In Progress: false
  Node Address: 192.168.1.2
  Manager Addresses:
   192.168.1.102:2377
   192.168.1.149:2377
   192.168.1.16:2377
   192.168.1.200:2377
   192.168.1.2:2377
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
 runc version: v1.1.9-0-gccaecfc
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.15.0-1041-raspi
 Operating System: Ubuntu 22.04.3 LTS
 OSType: linux
 Architecture: aarch64
 CPUs: 4
 Total Memory: 3.701GiB
 Name: scotty
 ID: 81713fa7-00ea-4d18-b417-7449b4e55cad
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  192.168.1.4:5000
  127.0.0.0/8
 Registry Mirrors:
  http://192.168.1.4/
 Live Restore Enabled: false

Additional Info

No response

bsponge commented 11 months ago

I cannot reproduce the issue

$ docker volume create docs/                                                                                                                                                   
Error response from daemon: create docs/: "docs/" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path

I have the same docker version

pcwilcox commented 11 months ago

Looks like it's a bug with the Ansible glusterfs volume plugin:

$ ansible localhost -m docker_volume -a "name='docs/' state=present driver=glusterfs driver_options='name=docs'"
localhost | CHANGED => {
    "changed": true,
    "volume": {
        "CreatedAt": "0001-01-01T00:00:00Z",
        "Driver": "glusterfs:latest",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/plugins/cd674c4f9ea79201fb39ea3289e991b4eb27d11e1a179bc09e84d380be7a9d9d/rootfs",
        "Name": "docs/",
        "Options": {
            "name": "docs"
        },
        "Scope": "local"
    }
}
$ docker volume ls
DRIVER             VOLUME NAME
glusterfs:latest   docs/
$ docker volume ls --format json
{"Availability":"N/A","Driver":"glusterfs:latest","Group":"N/A","Labels":"","Links":"N/A","Mountpoint":"/var/lib/docker/plugins/cd674c4f9ea79201fb39ea3289e991b4eb27d11e1a179bc09e84d380be7a9d9d/rootfs","Name":"docs/","Scope":"local","Size":"N/A","Status":"N/A"}

Either way there should be some way to remove it, right?

In case anyone else runs into this exact problem, it seems that manually executing the ansible plugin with state=absent does the job:


$ ansible localhost -m docker_volume -a "name='docs/' state=absent driver=glusterfs driver_options='name=docs'"
localhost | CHANGED => {
    "actions": [
        "Removed volume docs/"
    ],
    "changed": true
}```

I also found that Swarmkit was able to remove it.
thaJeztah commented 11 months ago

I cannot reproduce the issue

I think the devil is in the detail there; "invalid characters for a local volume name". ISTR that we restricted allowed names for local (built-in) volumes, but couldn't apply the same restrictions for volume-driver plugins as some plugins depended on special characters (or names containing slashes and other characters).

The daemon failing to remove this one may be related to an issue with gorilla/mux, which may strip the trailing hyphen when matching routes 🤔