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

Eldad Assis

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

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to write into host mounted folder from docker container

Running docker on Ubuntu: mounted host volume is not writable from container

docker data volume vs mounted host directory

Run executable from host within docker container

How to list Docker mounted volumes from within the container

Why is a shell within a docker container showing dmesg content from the host?

How to access postgres database on host from within docker container?

Get the host name from within the docker container from Python program

Detect AWS host environment from within a Docker Container

docker view directory within container

Copy file from host to docker container, executed in a script within the docker

Dockerfile: Copy directory from Windows host to docker container

Mount host directory into a docker container run from within docker container

Access docker container's directory from host

Copying file from host to Docker container's working directory

Docker - Rebooting raspberry pi host from within docker container

How to copy files to host-mounted directory in docker container

Replace a file from host to container with mounted volume

Docker: copy data from host to mounted host directory to access it from the running container

How to properly edit host directory from a docker container

Docker (Dockerfile): Share a directory from host to container

Get host IP Address from within docker container

How to get host info (CPU utilisation) from within a docker container?

exec-maven-plugin - copy directory from docker container to host

Host directory indicated as mounted, but empty in the container - what to check?

How to access file from host directory of docker container?

Access host from within a docker container

Docker container bind host directory

I want a directory accessible rwx both from the docker host and from within the container by default. How can I do this?