Can I control the owner of a bind-mounted volume in a docker image?

I believe at this point there is no way to set the UID and GID as a mount option in docker. But there are at least two ways of getting around this:

  1. Match UID and GID of the owner/user in the host and container. In your case, if the owner ID and GID on the host is say 1000, make sure the uid/gid of the owning user in the container has the same UID and GID, in this case 1000.

  2. Use the file access control list command getfacl – get the uid/gid of the workspace directory owner on the container, and use setfacl command to grant this id read/write permission at the host. You have to run setfacl on the host. This way the acl rights will propagate to the container. I would not recommend making any ownership changes at the container level, as that will mess up the owership on the host and it won’t be preserved the next time you launch a container from an image.

Remember, when it comes to file permissions only the numeric id matters.

Helpful links – permission inside containers

Leave a Comment

tech