Skip to content

Instantly share code, notes, and snippets.

@carlossg
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlossg/3bbdfaf007dc3d445307 to your computer and use it in GitHub Desktop.
Save carlossg/3bbdfaf007dc3d445307 to your computer and use it in GitHub Desktop.
Docker shared mount
$ sudo umount /mnt/xvdb
$ cat /proc/self/mountinfo | grep mnt
67 22 202:1 /mnt /mnt rw,relatime shared:1 - ext4 /dev/disk/by-uuid/e1d70192-1bb0-461d-b89f-b054e45bfa00 rw,discard,data=ordered
$ docker --version
Docker version 1.7.0-rc2, build 7ddecf7
$ docker run -d --name test -v /mnt/xvdb:/mnt busybox tail -f /dev/null
9865a125bd2d43cb06887e821e1b298fdee944bb72604edb2f5862619c1a200a
$ ls -laF /mnt/xvdb
total 8
drwxr-xr-x 2 root root 4096 Jun 17 20:05 ./
drwxr-xr-x 6 root root 4096 Jun 17 20:05 ../
$ docker exec test ls -alF /mnt
total 8
drwxr-xr-x 2 root root 4096 Jun 17 20:05 ./
drwxr-xr-x 23 root root 4096 Jun 17 20:16 ../
$ sudo mount /dev/xvdb /mnt/xvdb
$ ls -laF /mnt/xvdb
total 12
drwxr-xr-x 3 root root 4096 Jun 17 20:14 ./
drwxr-xr-x 6 root root 4096 Jun 17 20:05 ../
drwxr-xr-x 3 root root 4096 May 29 14:32 joc/
-rw-r--r-- 1 root root 0 Jun 17 20:14 test
$ docker exec test ls -alF /mnt
total 12
drwxr-xr-x 3 root root 4096 Jun 17 20:14 ./
drwxr-xr-x 23 root root 4096 Jun 17 20:16 ../
drwxr-xr-x 3 root root 4096 May 29 14:32 joc/
-rw-r--r-- 1 root root 0 Jun 17 20:14 test
# Files match in host and container
# If base dir is shared mounted after docker starts it doesn't update in the container
$ sudo umount /mnt
$ sudo service docker restart
docker stop/waiting
docker start/running, process 19113
$ sudo mount --bind /mnt /mnt
$ sudo mount --make-shared /mnt
$ sudo umount /mnt/xvdb
umount: /mnt/xvdb: not mounted
$ cat /proc/self/mountinfo | grep mnt
69 22 202:1 /mnt /mnt rw,relatime shared:1 - ext4 /dev/disk/by-uuid/e1d70192-1bb0-461d-b89f-b054e45bfa00 rw,discard,data=ordered
$ docker --version
Docker version 1.7.0-rc2, build 7ddecf7
$ docker run -d --name test -v /mnt/xvdb:/mnt busybox tail -f /dev/null
7a8c4d4599f533582386da6af324a6d6e18547bd915467b04b703d50f9adc008
$ ls -laF /mnt/xvdb
total 8
drwxr-xr-x 2 root root 4096 Jun 17 20:05 ./
drwxr-xr-x 6 root root 4096 Jun 17 20:05 ../
$ docker exec test ls -alF /mnt
total 8
drwxr-xr-x 2 root root 4096 Jun 17 20:05 ./
drwxr-xr-x 23 root root 4096 Jun 17 20:22 ../
$ sudo mount /dev/xvdb /mnt/xvdb
$ ls -laF /mnt/xvdb
total 12
drwxr-xr-x 3 root root 4096 Jun 17 20:14 ./
drwxr-xr-x 6 root root 4096 Jun 17 20:05 ../
drwxr-xr-x 3 root root 4096 May 29 14:32 joc/
-rw-r--r-- 1 root root 0 Jun 17 20:14 test
$ docker exec test ls -alF /mnt
total 8
drwxr-xr-x 2 root root 4096 Jun 17 20:05 ./
drwxr-xr-x 23 root root 4096 Jun 17 20:22 ../
$ sudo umount /mnt/xvdb
$ sudo umount /mnt
$ sudo mount --bind /mnt /mnt
$ sudo mount --make-shared /mnt
$ sudo service docker restart
docker stop/waiting
docker start/running, process 2349
$ sudo umount /mnt/xvdb
umount: /mnt/xvdb: not mounted
$ cat /proc/self/mountinfo | grep mnt
43 22 202:1 /mnt /mnt rw,relatime shared:1 - ext4 /dev/disk/by-uuid/e1d70192-1bb0-461d-b89f-b054e45bfa00 rw,discard,data=ordered
$ docker --version
Docker version 1.7.0-rc5, build f417602
$ docker run -d --name test -v /mnt/xvdb:/mnt busybox tail -f /dev/null
09d9350532354326e746242e5c7c76bfe6eadcc3f0571630219830de93e312ae
$ ls -laF /mnt/xvdb
total 8
drwxr-xr-x 2 root root 4096 Jun 17 16:23 ./
drwxr-xr-x 4 root root 4096 Jun 17 17:32 ../
$ docker exec test ls -alF /mnt
total 8
drwxr-xr-x 2 root root 4096 Jun 17 16:23 ./
drwxr-xr-x 23 root root 4096 Jun 17 20:28 ../
$ sudo mount /dev/xvdb /mnt/xvdb
$ ls -laF /mnt/xvdb
total 8
drwxr-xr-x 2 root root 4096 Jun 17 19:54 ./
drwxr-xr-x 4 root root 4096 Jun 17 17:32 ../
-rw-r--r-- 1 root root 0 Jun 17 19:54 test
$ docker exec test ls -alF /mnt
total 8
drwxr-xr-x 2 root root 4096 Jun 17 16:23 ./
drwxr-xr-x 23 root root 4096 Jun 17 20:28 ../
# NOTE that test file is not present
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment