Search code examples
dockerdocker-composedockerfiledocker-machine

docker run with volume changes directory permission to root


When I am running docker image, the artifacts directory which I mount, gets root permission. I want the artifacts to have the same permission as user. Is it possible to pass user as an argument while running docker image such that it creates artifacts directory with particular user permission?

This is how I run docker:

docker run --cap-add SYS_ADMIN --security-opt apparmor:unconfined -it -v /home/artifacts:/artifacts dock_img

drwxr-xr-x  2 root   root   4.0K Nov 16 13:58 artifacts

As this artifacts gets root permission, I am unable to process on it from my user login. Can someone help me in resolving this issue?


Solution

  • This is because you use the root user inside the container.

    You can use the -u param to set the user you use outside (e.g. -u `id -u $USER`), but if you need root inside the container, you have to chown it manually.