Search code examples
dockerfile-permissionsworkspacedocker-volume

Docker run changes the permission of the folder on the host machine


I have a path in my host /Users/bhav/workspace. I am the owner of it as well.

I run docker command as follows (as root user)

docker run -t -d -u root -w /Users/bhav/workspace -v /Users/bhav/workspace:/Users/bhav/workspacerw,z -v /Users/bhav/workspace@tmp:/Users/bhav/workspace@tmp:rw,z 7ff0d5f7b0ce

After i exit my container,

the permission of my workspace folder has changed to 'root'.

How to avoid/rectify this.


Solution

  • When you do -u root in your docker run, you are telling the container to run as root.

    Instead, try -u $(id -u):$(id -g) to have the container run as your user.

    Unfortunately this might not work if your image is not setup to run as different users, but often it will work (and if it's your own image, you can adjust things accordingly).

    Longer version: https://pythonspeed.com/articles/containers-filesystem-data-processing/