Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove mounted Docker volume directory on host without root permissions

I have the following problem.

I unintentionally mounted a Docker volume on a host machine on which I don’t have root permissions. Now, I get a ‘Permission denied’ error while trying to delete the directory, because the Docker container was created with the default root user.

x@y:~/app/xy$ ls -ld data
drwxr-xr-x 4 root root 4096 Apr  7 16:26 data
x@y:~/app/xy$ rm -rf data
rm: cannot remove 'data/data/binlog.000005': Permission denied
rm: cannot remove 'data/data/undo_002': Permission denied
rm: cannot remove 'data/data/server-key.pem': Permission denied
rm: cannot remove 'data/data/ibdata1': Permission denied
rm: cannot remove 'data/data/client-cert.pem': Permission denied
...
rm: cannot remove 'data/dump/client-key.pem': Permission denied
rm: cannot remove 'data/dump/ca.pem': Permission denied
x@y:~/app/xy$

Information: This Docker container was removed.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I looked for solutions, but found any yet.

Have you any suggestions how I can solve my problem?

Kind regards,
Martin

>Solution :

Go into the parent directory. Run a container as root and remove the directory

cd ~/app/xy
docker run --rm -v $(pwd):/app -w /app alpine rm -rf data

See this if you want to convince someone that they might as well give you root on the host: https://docs.docker.com/engine/security/#docker-daemon-attack-surface.
Of course that might back-fire and they’ll take away your docker privileges 🙂

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading