Answers: <p>At least in the *nix world the ownership (i.e. uid and gid) of a file/folder on a mounted filesystem doesn't change, it is the actual ownership from the host exporting that filesystem (if ownership is supported by that filesystem). </p>
  
  <p>Note that if the container has different user/group names matching the uid/gid of the file/folder they will appear under the container's names in <code>ls -l</code>, not as the host's names (or as numbers if no container names match the respective IDs).</p>
  
  <p>So if on the host machine the folder is owned by root, it will also be owned by root in the container (in other words it's nothing "special" about it being owned by root vs other users). The only way to allow the container app to write to the filesystem is to  change the ownership accordingly on the host system (or give it <code>other</code> write permissions).</p>
  
  <p>Maybe worth noting that if the host's filesystem itself doesn't support ownership, it can still be "faked" inside the container using the uid and gid mount options (in the *nix world). See <a href="https://unix.stackexchange.com/q/181260/117333">Ownership of a mount point</a>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2018-10-06T14:46:50.753Z
Answers: 2018-10-06T14:46:50.753Z
Answers: Dan Cornilescu
Body: <p>I have dockerized an application which accesses a folder "Folder1" inside the container. The folder is owned by a user "user1". When I bring the container up, I need to mount this folder over my host machine. Upon doing so, the ownership of "Folder1" inside the container changes to root as the corresponding mapped folder is under root's ownership on the host machine.</p>
  
  <p>This change of ownership makes the folder inaccessible to my application inside the container. Any idea how do I fix this?</p>
  
Comments: CC BY-SA 4.0
Comments: 2018-10-06T12:31:04.170Z
Comments: Is it ok to change the ownership of the folder on the host, or do you want your container to run as a user and access a host folder that's owned by root, without changing either?
Comments: BMitch
Comments: CC BY-SA 4.0
Comments: 2018-10-06T13:02:59.553Z
Comments: @BMitch : I just observed a weird thing. If I map the mounted folder to a folder that is not owned root but by any other user on the host machiner, then the folder inside the container retains the ownership. I wonder what's so special about root.
Comments: 7_R3X
Tags: <docker>
Title: Preserving ownership of a folder after mounting it
UserDisplayName: 7_R3X
ThreadText: # Preserving ownership of a folder after mounting it
  
  (Asked by: username_0 on 2018-10-06)
  
  I have dockerized an application which accesses a folder "Folder1" inside the container. The folder is owned by a user "user1". When I bring the container up, I need to mount this folder over my host machine. Upon doing so, the ownership of "Folder1" inside the container changes to root as the corresponding mapped folder is under root's ownership on the host machine.
  
  This change of ownership makes the folder inaccessible to my application inside the container. Any idea how do I fix this?
  
  **Tags:** docker
  
  > **Comments:**
  > **username_1**: Is it ok to change the ownership of the folder on the host, or do you want your container to run as a user and access a host folder that's owned by root, without changing either?  
  > **username_0**: @username_1 : I just observed a weird thing. If I map the mounted folder to a folder that is not owned root but by any other user on the host machiner, then the folder inside the container retains the ownership. I wonder what's so special about root.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-10-06. Score: 1 | Accepted answer
  
  At least in the \*nix world the ownership (i.e. uid and gid) of a file/folder on a mounted filesystem doesn't change, it is the actual ownership from the host exporting that filesystem (if ownership is supported by that filesystem).
  
  Note that if the container has different user/group names matching the uid/gid of the file/folder they will appear under the container's names in `ls -l`, not as the host's names (or as numbers if no container names match the respective IDs).
  
  So if on the host machine the folder is owned by root, it will also be owned by root in the container (in other words it's nothing "special" about it being owned by root vs other users). The only way to allow the container app to write to the filesystem is to change the ownership accordingly on the host system (or give it `other` write permissions).
  
  Maybe worth noting that if the host's filesystem itself doesn't support ownership, it can still be "faked" inside the container using the uid and gid mount options (in the \*nix world). See [Ownership of a mount point](https://unix.stackexchange.com/q/181260/117333).
  
  
  ---
  
  