7

I have a need to check if a directory in my running container is mounted from the host or not.
Example: using the docker run .... -v /host-data:/data .... command.

If not mounted, I want to warn the user that data on this directory will be lost when the container is terminated...

Eldad Assis
  • 10,464
  • 11
  • 52
  • 78

2 Answers2

7

I found a rough, but simple solution.

mount | grep '/data'

will result in 0 if found (which means it's mounted).
I added it to my entry-point script and it works as expected.

Ideas for improvements are welcome!

I hope this helps.

Eldad Assis
  • 10,464
  • 11
  • 52
  • 78
1
   mountVar=`mount | grep "$BLA"`
   if [ -z "$mountVar" ]
   then
      echo "$BLA not mounted  exit"
      exit
   else      
      echo "$BLA  mounted "

   fi
sherif
  • 2,282
  • 19
  • 21