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.
I looked for solutions, but found any yet.
Have you any suggestions how I can solve my problem?
Kind regards, Martin
CodePudding user response:
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 :)