Docker requires root escalation in order to execute an image, that crates some problem with files creation. Let’s say that we share a volume from host to docker and we create a file structure from inside docker.
This can be illustrated by an code snippet
docker run --rm -w $(pwd) -v $(pwd):$(pwd) debian \ bash -c "mkdir test && touch test/example"
# Running on host ls -la test total 8 drwxr-xr-x. 2 root root 4096 Jan 22 22:50 . drwxrwxr-x. 12 trzeci trzeci 4096 Jan 22 22:50 .. -rw-r--r--. 1 root root 0 Jan 22 22:50 example
# Running on host rm -fr test rm: cannot remove 'test/example': Permission denied
Why this is even an issue? I’ve found this problem mostly annoying on local setup, as I need to use
sudo for simple hose-keeping tasks. Another case when it’s very problematic is to use docker on Jenkins – as this prevents to remove workspace after a job is done.