Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind mounts with shared mount propogation don't work #3431

Open
1 of 2 tasks
segevfiner opened this issue Dec 31, 2018 · 23 comments
Open
1 of 2 tasks

Bind mounts with shared mount propogation don't work #3431

segevfiner opened this issue Dec 31, 2018 · 23 comments

Comments

@segevfiner
Copy link

segevfiner commented Dec 31, 2018

  • I have tried with the latest version of my channel (Stable or Edge)
  • I have uploaded Diagnostics
  • Diagnostics ID:

Expected behavior

The following works:

mkdir /tmp/foo
docker run --rm -it -v /tmp/foo:/foo:shared ubuntu:bionic

Actual behavior

It fails with the following error:

docker: Error response from daemon: linux mounts: path /foo is mounted on /foo but it is not a shared mount.

Information

  • macOS Version: 10.14.2

This is due to the osxfs mounts inside the HyperKit VM being mounted with private mount propagation. Entering the VM with screen and changing that using nsenter and mount --make-shared makes this work until you reboot the VM:

nsenter -t $(pgrep docker-init) -m mount --make-shared /tmp

Diagnostic logs

Docker for Mac: 2.0.0.0-mac81 (29211)

Steps to reproduce the behavior

mkdir /tmp/foo
docker run --rm -it -v /tmp/foo:/foo:shared ubuntu:bionic
@segevfiner segevfiner changed the title Bind mounts with shared bind propogation don't work Bind mounts with shared mount propogation don't work Jan 10, 2019
@docker-robott
Copy link
Collaborator

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale comment.
Stale issues will be closed after an additional 30d of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle stale

@lots0logs
Copy link

/remove-lifecycle stale

@docker-robott
Copy link
Collaborator

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale comment.
Stale issues will be closed after an additional 30d of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle stale

@lots0logs
Copy link

/remove-lifecycle stale

@ameyuuno
Copy link

@segevfiner Hi. Did you fix this problem with shared volume? If yes, how did you do that?

@lots0logs
Copy link

I used the workaround described by the OP (using nsenter)

@ameyuuno
Copy link

@lots0logs can you explain your solution?
I want to use google-drive-ocamlfuse on my Mac via Docker, but it uses :shared volume, and I do not understand how to make it works on Mac((

@freshpomelo
Copy link

Hello everyone,
It seems that I also have this issues.
image
I searched in Google, it seems that we could set MountFlags to "shared"
https://success.docker.com/article/not-a-shared-mount-error.
But I don't know how to do it on MacOS.

@segevfiner
Copy link
Author

segevfiner commented Oct 19, 2019

Workaround

screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty
mount --make-shared <mount_point>
# Ctrl-a Ctrl-\

You will need to do this on each Docker for Mac restart.

@lots0logs
Copy link

/remove-lifecycle stale

@lots0logs
Copy link

/lifecycle frozen

@scodeman
Copy link

Any chance to get a fix delivered on this one ?

@scodeman
Copy link

scodeman commented Oct 23, 2019

If using compose you can instantiate a small container image that makes the mount sharing work in the LinuxKit VM prior running the other containers.

Below worked for me:

./shared-mount/Dockerfile

FROM alpine:latest
ENV  MOUNTDIR=/mnt
CMD  nsenter -t $(pgrep docker-init) -m -- mount --verbose --make-shared ${MOUNTDIR}

./docker-compose.yml

---
version: '3.7'

services:
  shared-mount:
    build:
      context: ./shared-mount
    privileged: true
    stdin_open: true
    tty: true
    pid: "host"
    environment:
      - MOUNTDIR=/mnt
  listing-mount:
    image: "alpine:latest"
    command: ls /mnt
    depends_on:
        - shared-mount
    volumes:
      - type: bind
        source: "/mnt"
        target: "/mnt"
        bind:
         propagation: rshared
         consistency: delegated
         nocopy: true

@bugs181
Copy link

bugs181 commented May 24, 2020

Trying to figure out how to do this. My result:

docker-desktop:~# mount --make-shared /Users/levi/Desktop/docker/.../data
mount: /Users/levi/Desktop/docker/.../data: mount point does not exist.

@ghost
Copy link

ghost commented Dec 1, 2020

Reproduced in one line:

docker run --rm -it -v /tmp:/mnt/tmp:shared alpine sh

@segevfiner Re: Your workaround on Big Sur I get Operation not permitted running screen on the tty with sudo. Any ideas? Took me some time to find this issue.

I believe this may be the root cause of k3d-io/k3d#366


Docker Desktop 2.5.0.1
Darwin Kernel Version 20.2.0

@segevfiner
Copy link
Author

Docker for Mac changed things so that tty file no longer works. Try this to get a shell into the machine instead:

docker run -it --rm --privileged --pid=host justincormack/nsenter1

Might be enough then to just:

mount --make-shared /tmp

As that nsenter1 container might lend you in the docker daemon's namespace.

@jawadqur
Copy link

jawadqur commented Jun 3, 2021

I think this has resurfacced and not fixed yet in docker for mac. I can't use bind volumes on Mac.

@caugner
Copy link

caugner commented Jul 6, 2021

This issue also affects Docker for Windows, both inside WSL2 and outside.

edit: For me, a workaround was to run sudo mount --make-shared <path>

@mathieumuller
Copy link

mathieumuller commented Jul 15, 2021

This issue also affects Docker for Windows, both inside WSL2 and outside.

edit: For me, a workaround was to run sudo mount --make-shared <path>

Same issue for me today on WSL2, I tried @caugner workaround but it seems my path is not a valid mount point, does anyone have any other idea?

edit: I disabled the experimental feature "use Docker Compose V2" of my docker desktop and it is good now

@caugner
Copy link

caugner commented Jul 15, 2021

edit: I disabled the experimental feature "use Docker Compose V2" of my docker desktop and it is good now

For me, I had the issue even with that experimental feature was always disabled. Or they enabled it with an update, and disabled it again, without my interaction.

PS: I ran sudo mount --make-shared /, independently of the specific volume path, and that worked.

@sivang
Copy link

sivang commented Aug 11, 2021

I'm also looking to do a shared bind mount (to be able to capture source checkout and modifications from inside the container to the outside host) to no avail with almost every command / docker-compose combination here and in other resources on the web.
Is there a plan to fix this or work on this "feature" to make this consistent with the Linux behavior?

@GuerrillaCoder
Copy link

I ran into this issue and the actual reason was trailing slash "/" at end of path. I removed it and no longer got the error message. Leaving here in case anyone else googles the error and ends up here

@nrukavkov
Copy link

Any change to be fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests