docker / desktop-linux

Bug reports for Docker Desktop for Linux
https://docs.docker.com/desktop/linux/
73 stars 5 forks source link

Volume targets with trailing slashes fail #221

Open rpatterson opened 4 weeks ago

rpatterson commented 4 weeks ago

Description

The Docker daemon produces a misleading error message when a service uses a shared/top-level/named volume and the target: includes a trailing slash. Paths with trailing slashes are valid absolute paths so Docker should accept and handle them correctly. That this causes a failure indicates that the # dockerd daemon may not be using a proper filesystem path library when handling volume target paths and it seems like it should.

Reproduce

  1. Create the following compose project:

    # mkdir -pv /tmp/foo
    mkdir: created directory '/tmp/foo'
    # cat /tmp/foo/docker-compose.yml
    volumes:
    
      foo_volume:
        name: "foo_volume"
        driver: "local"
        driver_opts:
          type: "none"
          o: "bind"
          device: "/tmp/foo/"
    
    services:
    
      bar_service:
        image: "ubuntu"
        command: "ls -alR /tmp/foo/"
        volumes:
          - type: "volume"
            source: "foo_volume"
            target: "/tmp/foo"
  2. Note the resulting error when run:

    # docker volume rm "foo_volume" ; docker compose up
    foo_volume
    [+] Running 1/0
     ✔ Volume "foo_volume"          Created                                                                                                                                                  0.0s
     ⠋ Container foo-bar_service-1  Creating                                                                                                                                                 0.0s
    Error response from daemon: invalid mount config for type "bind": invalid mount path: 'foo_volume' mount path must be absolute
  3. Remove the trailing slash from target::

    # diff -u "/tmp/foo/docker-compose.yml~" "/tmp/foo/docker-compose.yml"
    --- /tmp/foo/docker-compose.yml~        2024-05-31 07:56:50.783871106 -0700
    +++ /tmp/foo/docker-compose.yml 2024-05-31 08:00:40.833869402 -0700
    @@ -16,4 +16,4 @@
         volumes:
           - type: "volume"
             source: "foo_volume"
    -        target: "/tmp/foo/"
    +        target: "/tmp/foo"
  4. Note that the container now runs as expected:

    # docker volume rm "foo_volume" ; docker compose up
    foo_volume
    [+] Running 2/2
     ✔ Volume "foo_volume"          Created                                                                                                                                                  0.0s
     ✔ Container foo-bar_service-1  Created                                                                                                                                                  0.6s
    Attaching to bar_service-1
    bar_service-1  | /tmp/foo/:
    bar_service-1  | total 12
    bar_service-1  | drwxrwxr-x 2 root root   80 May 31 15:00 .
    bar_service-1  | drwxrwxrwt 1 root root 4096 May 31 15:00 ..
    bar_service-1  | -rw-r--r-- 1 root root  317 May 31 15:00 docker-compose.yml
    bar_service-1  | -rw-r--r-- 1 root root  318 May 31 14:56 docker-compose.yml~
    bar_service-1 exited with code 0

Expected behavior

Docker should accept valid absolute paths as volume target: paths.

docker version

# docker version
Client: Docker Engine - Community
 Version:           26.1.3
 API version:       1.45
 Go version:        go1.21.10
 Git commit:        b72abbb
 Built:             Thu May 16 08:33:29 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.1.3
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.10
  Git commit:       8e96db1
  Built:            Thu May 16 08:33:29 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.32
  GitCommit:        8b3b7ca2e5ce38e8f31a34f35b2b68ceb8470d89
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

# docker info >./docker-info.log
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
# cat ./docker-info.log
Client: Docker Engine - Community
 Version:    26.1.3
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.14.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.27.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 34
  Running: 33
  Paused: 0
  Stopped: 1
 Images: 38
 Server Version: 26.1.3
 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: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 nvidia runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8b3b7ca2e5ce38e8f31a34f35b2b68ceb8470d89
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 5.15.153.1-microsoft-standard-WSL2
 Operating System: Pop!_OS 22.04 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 31.31GiB
 Name: library.moodysalonnet
 ID: 930e1cc3-4d06-44a2-828b-b203b25ad7a9
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Diagnostics ID

N/A

Additional Info

No *diagnose* tool is available from this installation:

# aptitude search -F '%p' ~i~ndocker
docker-buildx-plugin
docker-ce
docker-ce-cli
docker-ce-rootless-extras
docker-compose-plugin
nvidia-docker2
# aptitude search -F '%p' '~i~ndocker' | xargs -d '\n' -- dpkg -L | grep 'diagnose'
rpatterson commented 4 weeks ago

A related thought, it seems like the error message could also be improved. It could clearly indicate whether the error is from creating the volume or using it in a container and it could indicate whether the path error is for the source/device or the target.