0

I created a docker container that shares a folder with its host using the following command:

docker run  -dit -P -v $(pwd):/home/shared ubuntu

The container became unresponsive so I deleted it and pruned it using the following steps mentioned here:

docker rm $(docker ps -aq)
docker rmi $(docker images -q)
docker system prune

Now, I would like to delete the file that resides on the host and was created by the container. However, I keep getting this error msg:

rm file1
rm: remove write-protected regular file ‘file1’? Y 
rm: cannot remove ‘file1’: Permission denied

I don't have sudo privilege on this host, can I do something about it, or do I need to ask the system administrator's help for this?

Thank you

  • You can `docker run` a container as root and make arbitrary changes to the host filesystem through mounted volumes. You could use this to delete the file the same way you created it. (...or add yourself to the host's `/etc/sudoers`, or...) – David Maze Sep 01 '20 at 13:35

1 Answers1

0

The Docker daemon runs as root and your user(apparently in the docker group, given the lack of sudo and the file permission issues) has access to the API(typically exposed via a local unix socket). Through the docker API you should be able to delete the created files.

If it is truly a volume, you should simply be able to use the docker volume rm command.

docker volume rm <your-volume>

If you instead mounted a path from the host, you should be able to launch a new container to delete the file(s), re-using the same mount point(for instance, start a basic bash container with docker run, rm the specified files, and then remove the new container).

akenion
  • 805
  • 1
  • 5
  • 9