Unable to find user test1原因是你images里没有-u的username的用户,所以才会报错。
[root@ip-10-10-125-6 docker_code]# docker exec -it test_new4 bash root@b8efc9a9471a:/# useradd test_new4 root@b8efc9a9471a:/# id uid=0(root) gid=0(root) groups=0(root) root@b8efc9a9471a:/# cat /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/bin/sh man:x:6:12:man:/var/cache/man:/bin/sh lp:x:7:7:lp:/var/spool/lpd:/bin/sh mail:x:8:8:mail:/var/mail:/bin/sh news:x:9:9:news:/var/spool/news:/bin/sh uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh proxy:x:13:13:proxy:/bin:/bin/sh www-data:x:33:33:www-data:/var/www:/bin/sh backup:x:34:34:backup:/var/backups:/bin/sh list:x:38:38:Mailing List Manager:/var/list:/bin/sh irc:x:39:39:ircd:/var/run/ircd:/bin/sh gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh nobody:x:65534:65534:nobody:/nonexistent:/bin/sh libuuid:x:100:101::/var/lib/libuuid:/bin/sh sshd:x:101:65534::/var/run/sshd:/usr/sbin/nologin root@b8efc9a9471a:/# useradd test_new4 root@b8efc9a9471a:/# cat /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/bin/sh man:x:6:12:man:/var/cache/man:/bin/sh lp:x:7:7:lp:/var/spool/lpd:/bin/sh mail:x:8:8:mail:/var/mail:/bin/sh news:x:9:9:news:/var/spool/news:/bin/sh uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh proxy:x:13:13:proxy:/bin:/bin/sh www-data:x:33:33:www-data:/var/www:/bin/sh backup:x:34:34:backup:/var/backups:/bin/sh list:x:38:38:Mailing List Manager:/var/list:/bin/sh irc:x:39:39:ircd:/var/run/ircd:/bin/sh gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh nobody:x:65534:65534:nobody:/nonexistent:/bin/sh libuuid:x:100:101::/var/lib/libuuid:/bin/sh sshd:x:101:65534::/var/run/sshd:/usr/sbin/nologin test_new4:x:1000:1000::/home/test_new4:/bin/sh然后提交此镜像
[root@ip-10-10-125-6 docker_code]# docker commit --pause=false b8efc9a9471a test_new4:1.0 be9fbe7a33ab03230b6bce5d3e83c901f7f6d0f8f16a6db21d196a6a2b4d73b1 [root@ip-10-10-125-6 docker_code]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE test_new4 1.0 be9fbe7a33ab 4 minutes ago 269.8 MB之后在使用此镜像生产一个容器24,然后启动的时候指定使用test_new4用户
[root@ip-10-10-125-6 docker_code]# docker run --restart always -d -u test_new4 --name='24' test_new4:1.0 /usr/bin/supervisord a639b74bd664c34466e257ecd898374230658d0c6e81d9a71d458ff6bdec3f4a [root@ip-10-10-125-6 docker_code]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a639b74bd664 test_new4:1.0 "/usr/bin/supervisor 3 seconds ago Up 2 seconds 24 fb2fdbed8f4d docker.ops-chukong.com:5000/ubuntu-12.04-base:1.0 "/usr/bin/supervisor 19 hours ago Up 19 hours cluster-test2.0 68f4f61af646 docker.ops-chukong.com:5000/ubuntu-12.04-base:1.0 "/usr/bin/supervisor 39 hours ago Up 39 hours cluster-test1.0 b8efc9a9471a docker.ops-chukong.com:5000/ubuntu-12.04-base:1.0 "/usr/bin/supervisor 2 weeks ago Up 2 weeks test_new4最后进入容器测试看看
[root@ip-10-10-125-6 docker_code]# docker exec -it 24 /bin/bash test_new4@a639b74bd664:/$ id uid=1000(test_new4) gid=1000(test_new4) groups=1000(test_new4),0(root) test_new4@a639b74bd664:/$ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND 1000 1 0.1 0.0 46936 13524 ? Ss 02:39 0:00 /usr/bin/python /usr/bin/supervisord 1000 11 0.0 0.0 18048 3236 ? Ss 02:39 0:00 /bin/bash 1000 58 0.0 0.0 15292 2116 ? R+ 02:43 0:00 ps aux test_new4@a639b74bd664:/$ exit exit关于-u的介绍,可以看官方文档,也可以参考下面的
The default user within a container is root (id = 0), but if the developer created additional users, those are accessible too. The developer can set a default user to run the first process with the Dockerfile USER instruction, but the operator can override it:收起
第10行 ”10.bash-4.1# cat /etc/supervisord.conf“這是在docker 的配置嗎?
/usr/lib/python2.6/site-packages/supervisor-3.1.3-py2.6.egg/supervisor/options.py:296: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security. 'Supervisord is running as root and it is searching ' 2015-07-30 09:10:35,569 CRIT Supervisor running as root (no user in config file) 2015-07-30 09:10:35,575 INFO supervisord started with pid 136 2015-07-30 09:10:36,580 INFO spawned: 'rpcbind' with pid 139 2015-07-30 09:10:36,634 INFO exited: rpcbind (exit status 0; not expected) 2015-07-30 09:10:37,639 INFO spawned: 'rpcbind' with pid 147 2015-07-30 09:10:37,693 INFO exited: rpcbind (exit status 0; not expected) 2015-07-30 09:10:39,699 INFO spawned: 'rpcbind' with pid 155 2015-07-30 09:10:39,755 INFO exited: rpcbind (exit status 0; not expected) 2015-07-30 09:10:42,762 INFO spawned: 'rpcbind' with pid 163 2015-07-30 09:10:42,819 INFO exited: rpcbind (exit status 0; not expected) 2015-07-30 09:10:43,821 INFO gave up: rpcbind entered FATAL state, too many start retries too quickly產生新images 步驟
step1 [root@docker ~]# docker run -it --privileged=true --add-host=rsnis1:172.29.22.200 --dns=172.29.17.10 -v /docker:/docker rpcbindstart1
step 2 [root@285e6e87c934 S0588]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 14780 1912 ? Ss 09:06 0:00 /bin/bash root 324 0.0 0.0 16664 1120 ? R+ 09:38 0:00 ps aux
step3 config --> /etc/supervisord.conf [root@285e6e87c934 S0588]# cat /etc/supervisord.conf [supervisord] nodaemon=true pidfile=/var/log/supervisord/supervisord.pid logfile=/var/log/supervisord/supervisord.log [program:rpcbind] command= /etc/init.d/rpcbind start autostart=true autorestart=true redirect_stderr=true stdout_logfile=/var/log/supervisord/rpcbind_stdout.log stderr_logfile=/var/log/supervisord/rpcbind_stderr.log
step 4 test supervisord [root@285e6e87c934 S0588]# supervisord -c /etc/supervisord.conf 2015-07-30 09:42:03,235 CRIT Supervisor running as root (no user in config file) 2015-07-30 09:42:03,241 INFO supervisord started with pid 326 2015-07-30 09:42:04,245 INFO spawned: 'rpcbind' with pid 329 2015-07-30 09:42:04,444 INFO exited: rpcbind (exit status 0; not expected) 2015-07-30 09:42:05,447 INFO spawned: 'rpcbind' with pid 361 2015-07-30 09:42:05,488 INFO exited: rpcbind (exit status 0; not expected) 2015-07-30 09:42:07,492 INFO spawned: 'rpcbind' with pid 369 2015-07-30 09:42:07,533 INFO exited: rpcbind (exit status 0; not expected) 2015-07-30 09:42:10,540 INFO spawned: 'rpcbind' with pid 377 2015-07-30 09:42:10,590 INFO exited: rpcbind (exit status 0; not expected) 2015-07-30 09:42:11,591 INFO gave up: rpcbind entered FATAL state, too many start retries too quickly ^Z [1]+ Stopped supervisord -c /etc/supervisord.conf [root@285e6e87c934 S0588]# bg [1]+ supervisord -c /etc/supervisord.conf & [root@285e6e87c934 S0588]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 14780 1912 ? Ss 09:06 0:00 /bin/bash root 326 1.7 0.0 102548 12304 ? S 09:42 0:00 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf rpc 358 0.4 0.0 19028 616 ? Ss 09:42 0:00 rpcbind root 385 0.0 0.0 16660 1124 ? R+ 09:42 0:00 ps aux [root@285e6e87c934 S0588]#
step 5 commit [root@docker ~]# docker commit 285e6e87c934 rpcbindstart2 5ed87b1c91d0cfbbe1cf3d9b0667e6e4dcae6d862006de2b57a103fb1e50d041 [root@docker ~]#
step6 start new docker [root@docker ~]# docker run -it --privileged=true --add-host=rsnis1:172.29.22.200 --dns=172.29.17.10 -v /docker:/docker rpcbindstart2 Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning. [root@115d99ea5394 S0588]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 3.6 0.0 14780 1768 ? Ss 09:43 0:00 /bin/bash root 15 0.0 0.0 16664 1120 ? R+ 09:43 0:00 ps aux [root@115d99ea5394 S0588]#daemon依然沒有帶起來,不知道是不是supervisord 報錯引起的!收起
[root@ip-10-10-125-8 ~]# docker exec -it test1 bash bash-4.1# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 99524 15292 ? Ss Jun22 10:14 /usr/bin/python /usr/bin/supervisord root 11 0.0 0.0 66704 5868 ? S Jun22 0:41 /usr/sbin/sshd -D root 22 0.0 0.0 175988 6652 ? Sl Jun22 0:11 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5 root 23 0.0 0.0 20468 2308 ? Ss Jun22 0:09 crond root 23877 0.0 0.0 11496 2668 ? Ss 16:55 0:00 bash root 23899 0.0 0.0 13384 1848 ? R+ 16:56 0:00 ps aux bash-4.1# cat /etc/supervisord.conf [supervisord] nodaemon=true pidfile=/var/log/supervisord/supervisord.pid logfile=/var/log/supervisord/supervisord.log [program:sshd] command=/usr/sbin/sshd -D autostart=true autorestart=true redirect_stderr=true stdout_logfile=/var/log/supervisord/sshd_stdout.log stderr_logfile=/var/log/supervisord/sshd_stderr.log [program:crond] command=/etc/init.d/crond start autostart=true autorestart=true redirect_stderr=true stdout_logfile=/var/log/supervisord/crond_stdout.log stderr_logfile=/var/log/supervisord/crond_stderr.log [program:rsyslog] command=/etc/init.d/rsyslog start autostart=true autorestart=true redirect_stderr=true stdout_logfile=/var/log/supervisord/rsyslog_stdout.log stderr_logfile=/var/log/supervisord/rsyslog_stderr.log收起
[root@67562e5373fc S0588]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.2 0.0 14780 1836 ? Ss 08:38 0:00 /bin/bash root 17 0.0 0.0 16664 1116 ? R+ 08:39 0:00 ps auxPS: 是docker 啟動后自動帶起相關daemon,而非手動執行!收起