Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - check within the container if a directory is mounted from the host or not

Tags:

docker

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...

like image 853
Eldad Assis Avatar asked Sep 21 '16 15:09

Eldad Assis


1 Answers

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.

like image 178
Eldad Assis Avatar answered Nov 15 '22 04:11

Eldad Assis