简体   繁体   中英

Docker user permissions in mounted volumes

I am running some docker images that need to mount a local volume and make changes there. I am launching the container with a typical

docker run -it -v $(pwd):/root/foo ${IMAGENAME} ./script.sh

The problem is that new files in host directory have root permission/owner. I would prefer avoiding any configuration except from adding something to the command line.

Changing the file permissions after executing would not be clean enough and may require root permissions anyway.

Ideally I would like something like --userns-remap but applied when I execute docker run and mapping the container root to the user that launched the container.

Any suggestions?

You have different options to fix this. 1)Without modifying the docker image or the Dockerfile, you can change the permission of the files in the folder with "$ sudo chmod -R 777 /path/foo"

or if you want to be sure that whoever takes this image is ok with permissions, do some changes to the Dockerfile, like change permissions inside the container or write the file in a /home/foo folder.

I hope you understood what to do, or at least got an idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM