在组“usergroup1”中以名称“username1”的用户启动docker容器时.
$username1>docker run -v /homes/username1/output:output outputter
使用root作为所有者创建文件.
我需要在Dockerfile或启动选项中做些什么来确保输出文件夹中的文件rigth与localuser:group相同,在这种情况下username1:usergroup1?
最佳答案
如this project中所述:
原文链接:https://www.f2er.com/docker/436180.htmlBy default,our docker containers run as the root user. Files created or modified by the container will thus become owned by the
root
user,even after quitting the container.
To avoid this problem,it is necessary to run the container using a non-root user.If the host machine user has a UID other than 1000 (or 0,for root),the user should specify their UID when running docker,e.g.
docker run -d -P -v $(pwd):/home/$USER/foo \
-e USER=$USER -e USERID=$UID rocker/rstudio
to avoid changing the permissions in the linked volume on the host
这是有效的,因为project Dockerfile,当启动容器时,creates a user with the same uid(名称并不重要)
## (Docker cares only about uid,not username; diff users with same uid = confusion)
if [ "$USERID" -ne 1000 ]
## Configure user with a different USERID if requested.
then
echo "creating new $USER with UID $USERID"
useradd -m $USER -u $USERID
mkdir /home/$USER
chown -R $USER /home/$USER