How to list Docker mounted volumes from within the container

Leo Gallucci picture Leo Gallucci · Jun 4, 2015 · Viewed 12k times · Source

I want to list all container directories that are mounted volumes.

I.e. to be able to get similar info I get from

docker inspect --format "{{ .Volumes }}" <self>

But from within the container and without having docker installed in there.

I tried cat /proc/mounts, but I couldn't find a proper filter for it.

Answer

Ryan Calhoun picture Ryan Calhoun · Nov 14, 2017

(EDIT - this may no longer work on Mac) If your Docker host is OS X, the mounted volumes will be type osxfs (or fuse.osxfs). You can run a

mount | grep osxfs | awk '{print $3}'

and get a list of all the mounted volumes.

If your Docker host is Linux (at least Ubuntu 14+, maybe others), the volumes appear to all be on /dev, but not on a device that is in your container's /dev filesystem. The volumes will be alongside /etc/resolv.conf, /etc/hostname, and /etc/hosts. If you do a mount | grep ^/dev to start, then filter out any of the files in ls /dev/*, then filter out the three files listed above, you should be left with host volumes.

mount | grep ^/dev/ | grep -v /etc | awk '{print $3}'

My guess is the specifics may vary from Linux to Linux. Not ideal, but at least possible to figure out.