docker用户通过相同的UID与宿主机用户建立对应关系
环境[root@m6 appslog]# uname -aLinux m6 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux[root@m6 appslog]# docker --versionDocker version 1.13.1, build b2f74b...
环境
[root@m6 appslog]# uname -a
Linux m6 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@m6 appslog]# docker --version
Docker version 1.13.1, build b2f74b2/1.13.1
启动容器,并映射要用到的目录
root@m6 overlay]# docker run -it -v /tmp/appslog:/usr/local/tomcat/logs tomcatapps
添加测试用户,指定UID
[root@m6 apps2]# useradd -u 10086 uid1
改变文件的所有者
[root@m6 appslog]# pwd
/tmp/appslog
[root@m6 appslog]# chown -R uid1:uid1 files
[root@m6 appslog]# ls -l
总用量 20
drwxr-xr-x 2 uid1 uid1 6 9月 2 16:34 files
进入容器建立相同UID的帐号
[root@m6 appslog]# docker attach 25bdc1e3378e
root@25bdc1e3378e:/usr/local/tomcat/logs# useradd -u 10086 uid1
此时与宿主机UID相同的所有者用户有权限读写,其它用户写入拒绝
root@25bdc1e3378e:/usr/local/tomcat/logs# su uid1
$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534::/nonexistent:/bin/false
apps:x:1000:1000::/home/apps:
t1:x:1001:1001::/home/t1:
apps2:x:1002:1002::/home/apps2:
uid1:x:10086:10086::/home/uid1:
$ pwd
/usr/local/tomcat/logs
$ cd files
$ echo "hello" >> hello.txt
$ exit
root@25bdc1e3378e:/usr/local/tomcat/logs# su t1
$ echo "hello" >> hello.txt
sh: 1: cannot create hello.txt: Permission denied
退出容器,查看创建文件的用户为uid1,说明映射关系形成
[root@m6 appslog]# ls -l files/
总用量 4
-rw-r--r-- 1 uid1 uid1 6 9月 2 16:41 hello.txt
更多推荐
所有评论(0)