docker / for-mac

Bug reports for Docker Desktop for Mac
https://www.docker.com/products/docker#/mac
2.44k stars 118 forks source link

VirtioFS does not allow bind mount to be unmounted while container is running #7133

Open davidjayb opened 10 months ago

davidjayb commented 10 months ago

Description

When using VirtioFS for file sharing I am unable to dynamically mount/unmount my device. If I try to start the container without the device mounted:

Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /mnt/garmin

After mounting the device I am able to run the container. However, I am unable to unmount the device while running the container -- MacOS will warn that the device is still in use. If I force the device to be unmounted I will get a bad file descriptor until I restart the docker engine:

python@eceff874889a:/python$ ls /mnt
ls: cannot access '/mnt/garmin': Bad file descriptor

And this error will persist after I restart the container and/or re-mount the device. I have to restart the docker engine in order to fix the issue.

If I switch to osxfs I am able to mount and unmount at will.

Reproduce

I am connecting my Garmin watch to my docker container. A custom mount point is being used to avoid issues with the volume folder not existing under /Volumes/GARMIN when the container is started. Example fstab configuration via sudo vifs:

LABEL=GARMIN /Users/<user>/mnt/garmin msdos rw 0 0

This will allow the device to be mounted at the ~/mnt/garmin folder.

You can then connect your watch or issue a diskutil mount command to an already connected device. In my case it is on disk4:

diskutil mount /dev/disk4

Alternatively you can unmount the device and mount it without modifying your fstab configuration:

sudo umount /dev/disk4
sudo mount -t msdos /dev/disk4 /Users/<user>/mnt/garmin

Here is my Docker Compose volume configuration:

volumes:
  - type: bind
    source: /mnt/garmin
    target: /mnt/garmin
    bind:
      propagation: rshared

With this configuration I should be able to start the container without the device mounted, mount the device while the container is running, and unmount the device once I am finished with it while keeping the container running.

Expected behavior

No response

docker version

Client: Docker Engine - Community
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.21.3
 Git commit:        afdd53b4e3
 Built:             Thu Oct 26 07:06:42 2023
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.26.1 (131620)
 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:15 2023
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.25
  GitCommit:        d8f198a4ed8892c764191ef7b3b06d8a2eeb5c7f
 runc:
  Version:          1.1.10
  GitCommit:        v1.1.10-0-g18a0cb0
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client: Docker Engine - Community
 Version:    24.0.7
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.12.0-desktop.2
    Path:     /Users/<user>/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.23.3-desktop.2
    Path:     /Users/<user>/.docker/cli-plugins/docker-compose
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     /Users/<user>/.docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.21
    Path:     /Users/<user>/.docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  0.1
    Path:     /Users/<user>/.docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v0.1.0-beta.10
    Path:     /Users/<user>/.docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/<user>/.docker/cli-plugins/docker-sbom
  scan: Docker Scan (Docker Inc.)
    Version:  v0.26.0
    Path:     /Users/<user>/.docker/cli-plugins/docker-scan
  scout: Docker Scout (Docker Inc.)
    Version:  v1.2.0
    Path:     /Users/<user>/.docker/cli-plugins/docker-scout

Server:
 Containers: 11
  Running: 4
  Paused: 0
  Stopped: 7
 Images: 43
 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: cgroupfs
 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: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: d8f198a4ed8892c764191ef7b3b06d8a2eeb5c7f
 runc version: v1.1.10-0-g18a0cb0
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 6.5.11-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 4
 Total Memory: 3.837GiB
 Name: docker-desktop
 ID: 7657e281-47b9-4be1-87ef-edae4dd78e24
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: daemon is not using the default seccomp profile

Diagnostics ID

EBE543F9-393F-49F2-B1BB-FE01D27D3061/20240115002541

Additional Info

No response

fredericdalleau commented 10 months ago

It looks like a system limitation, can you issue in a privileged container echo 2 > /proc/sys/vm/drop_caches before unmounting to see if the VM is holding any file open on the mount. Also in the compose file, maybe you can bind $HOME/mnt, in case a reference to the host mount point is still hold by the vm.