Skip to content

Instantly share code, notes, and snippets.

@jpetazzo
Created July 3, 2014 12:14
Show Gist options
  • Save jpetazzo/830e45a6c35b36b4d916 to your computer and use it in GitHub Desktop.
Save jpetazzo/830e45a6c35b36b4d916 to your computer and use it in GitHub Desktop.
Shared Mounts Experiment

Get little rootfs from https://github.com/jpetazzo/docker-busybox/blob/master/tarmaker-buildroot/rootfs.tar

mkdir c1 c2
sudo tar -C c1 -xf rootfs.tar
sudo tar -C c2 -xf rootfs.tar

Now we will prepare c1 to host a shared mount with c2:

mount -o bind c1/mnt c1/mnt
mount --make-rshared c1/mnt
mount -o bind c1/mnt c2/mnt

Now let's start c1 and make our mount:

sudo unshare --mount chroot c1 sh
mount -t tmpfs none mnt
touch mnt/hello

Let's start c2 and see (in different terminal):

sudo unshare --mount chroot c2 sh
ls mnt # hello is there

In the host namespace, we can safely unmount c1/tmp and c2/tmp; however, if we do so, it becomes impossible to share them further with other containers.

Conclusion: if we make all volumes shared mounts before handing them to the container, the container can mount something on top of them, and that thing will be visible from the host, and share-able with other containers. They will have to be unmounted when the container exits, however.

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