Docker Community Forums

Share and learn in the Docker community.

How to detect if a volume is actually mounted


(Rgerhards) #1


I am new to docker, so I may just have missed this from the documentation.

I am creating a container where I absolutely want to ensure that a volume is actually mounted and the dockerized APP does not write into the data layer of the container itself.

Are there any APIs or other ways that an application can detect that “status” of a given file system path?


(Think) #2

do the pragmatic way…start your container in read-only mode. this way you can ensure, that just on volumes (or tmpfs) is written to.

(Rgerhards) #3

OK, is there any way I can enforce starting up read-only? This container is for wide consumption and I actually want to prevent potential user errors. The actual project is to create an “official” rsyslog container.

(Think) #4

start and try to write a file to “/”? :slight_smile:

(Rgerhards) #5

ok, thanks, that’s a workaround. I admit I would prefer to have an official capability to say “this container needs to be read-only”. It would also be good to have a way to check volumes as originally said, but that’s easier to miss :wink: Is there really no way to make this happen?

(Sam) #6

you can of course write out a message and then exit the entrypoint program so the container stops…

(Rgerhards) #7

sorry for the confusion. I know I can do this. I was thinking a Dockerfile “command” like “FORCE-READ-ONLY” or something like a hypervisor call where I can say “hey docker, tell me if I am read only”, “hey docker, tell me if dir /some/path is a mounted volume” - along these lines…

(Rgerhards) #8

And by “FORCE-READ-ONLY” I mean that docker run would automtically force the container to be read only.

Let me add this to avoid yet another confusion. And thanks a lot for sharing your insight. As I said, I just get up to speed on docker. What I really miss is this kind of hypervisor API (and, yes, I know what a hypervisor is and what a process is ;-)).


(Syconet) #9

Can I know what type of volume you have mounted?