Docker Community Forums

Share and learn in the Docker community.

Cannot change owner and permissions of a volume inside container


(Clns) #1

Using Docker for Windows with Linux containers, it appears that volumes are always mounted as root inside containers.
Trying to change either the owner (with chown) or the permissions (with chmod) doesn’t return any error but nothing changes.

Maybe this is a well know thing but I can’t find exact information on this subject anywhere. How does these permissions work?
On a Mac for example, things are a little different. Volumes get mounted as root but the owner can be changed using chown. chmod on a Mac sometimes succeeds, sometimes it returns “Operation not permitted”.

A use case is when trying to use Apache with a mounted volume as document root. It won’t work because all files are owned by root.

A quick replication example (in PowerShell):

## Prepare:
$ cd ~; mkdir test-owner-dockr; cd test-owner-dockr
$ echo "Testing ownership and permissions" >
$ docker run -d --name testowner -v "$(pwd):/tmp/win" -w /tmp/win busybox sh -c 'while [ true ]; do date; sleep 1; done'

## View original:
$ docker exec testowner ls -l
total 1
-rwxr-xr-x    1 root     root            72 Jan  5 15:51

## Change permission (nothing happens, command succeeds):
$ docker exec testowner sh -c 'chmod 0777 && ls -l'
total 1
-rwxr-xr-x    1 root     root            72 Jan  5 15:51

## Change ownership (nothing happens, command succeeds):
$ docker exec testowner sh -c 'chown nobody && ls -l'
total 1
-rwxr-xr-x    1 root     root            72 Jan  5 15:51

(Markob83) #2

I’m having the same issue today on Windows 10. Works fine on my macbook.

(Clns) #3

But is this an issue or is it expected?

(Lenks) #4

Hi. I’m having the same problem. Did anyone found a solution?

(Clns) #5

Is there any update on this issue?

(Pcsit) #6

i am also looking for a solution to this issue for quite some time now - some services wont run without having the permissions set correctly.

does anyone have a workaround?

(Ageraluon) #7

See here:

This is a current limitation in Docker For Windows which seems to currently have no workaround…