docker运行容器后agetty进程cpu占用率100%
1、最近在使用docker容器的时候,发现宿主机的agetty进程cpu占用率达到100%

在Google上搜了下,引起这个问题的原因是在使用"docker run"运行容器时使用了"/sbin/init"和"--privileged"参数。
使用/sbin/init启动容器并加上--privileged参数,相当于docker容器获得了宿主机的全权委托权限。这时docker容器内部的init与宿主机的init产生了混淆。
# 引用google到的一段话:
I've done all my testing on them without using --privileged, especially since that's so dangerous (effectively, you're telling this second init process on your system that it's cool to go ahead and manage your system resources, and then giving it access to them as well). I always think of --privileged as a hammer to be used very sparingly.
出于对安全的考虑,在启动容器时,docker容器里的系统只具有一些普通的linux权限,并不具有真正root用户的所有权限。而--privileged=true参数可以让docker容器具有linux root用户的所有权限。
为了解决这个问题,docker后来的版本中docker run增加了两个选项参数"--cap-add"和"--cap-drop"。
--cap-add : 获取default之外的linux的权限
--cap-drop: 放弃default linux权限
从docker官网的文档中可以查到,docker容器具有的default权限及--cap-add可以获取到的扩展权限如下:
Default 权限:
|
Capability Key |
Capability Description |
|
SETPCAP |
Modify process capabilities. |
|
MKNOD |
Create special files using mknod(2). |
|
AUDIT_WRITE |
Write records to kernel auditing log. |
|
CHOWN |
Make arbitrary changes to file UIDs and GIDs (see chown(2)). |
|
NET_RAW |
Use RAW and PACKET sockets. |
|
DAC_OVERRIDE |
Bypass file read, write, and execute permission checks. |
|
FOWNER |
Bypass permission checks on operations that normally require the file system UID of the process to match the UID of the file. |
|
FSETID |
Don’t clear set-user-ID and set-group-ID permission bits when a file is modified. |
|
KILL |
Bypass permission checks for sending signals. |
|
SETGID |
Make arbitrary manipulations of process GIDs and supplementary GID list. |
|
SETUID |
Make arbitrary manipulations of process UIDs. |
|
NET_BIND_SERVICE |
Bind a socket to internet domain privileged ports (port numbers less than 1024). |
|
SYS_CHROOT |
Use chroot(2), change root directory. |
|
SETFCAP |
Set file capabilities. |
通过--cap-add获取到的权限:
|
Capability Key |
Capability Description |
|
SYS_MODULE |
Load and unload kernel modules. |
|
SYS_RAWIO |
Perform I/O port operations (iopl(2) and ioperm(2)). |
|
SYS_PACCT |
Use acct(2), switch process accounting on or off. |
|
SYS_ADMIN |
Perform a range of system administration operations. |
|
SYS_NICE |
Raise process nice value (nice(2), setpriority(2)) and change the nice value for arbitrary processes. |
|
SYS_RESOURCE |
Override resource Limits. |
|
SYS_TIME |
Set system clock (settimeofday(2), stime(2), adjtimex(2)); set real-time (hardware) clock. |
|
SYS_TTY_CONFIG |
Use vhangup(2); employ various privileged ioctl(2) operations on virtual terminals. |
|
AUDIT_CONTROL |
Enable and disable kernel auditing; change auditing filter rules; retrieve auditing status and filtering rules. |
|
MAC_OVERRIDE |
Allow MAC configuration or state changes. Implemented for the Smack LSM. |
|
MAC_ADMIN |
Override Mandatory Access Control (MAC). Implemented for the Smack Linux Security Module (LSM). |
|
NET_ADMIN |
Perform various network-related operations. |
|
SYSLOG |
Perform privileged syslog(2) operations. |
|
DAC_READ_SEARCH |
Bypass file read permission checks and directory read and execute permission checks. |
|
LINUX_IMMUTABLE |
Set the FS_APPEND_FL and FS_IMMUTABLE_FL i-node flags. |
|
NET_BROADCAST |
Make socket broadcasts, and listen to multicasts. |
|
IPC_LOCK |
Lock memory (mlock(2), mlockall(2), mmap(2), shmctl(2)). |
|
IPC_OWNER |
Bypass permission checks for operations on System V IPC objects. |
|
SYS_PTRACE |
Trace arbitrary processes using ptrace(2). |
|
SYS_BOOT |
Use reboot(2) and kexec_load(2), reboot and load a new kernel for later execution. |
|
LEASE |
Establish leases on arbitrary files (see fcntl(2)). |
|
WAKE_ALARM |
Trigger something that will wake up the system. |
|
BLOCK_SUSPEND |
Employ features that can block system suspend. |
所以,在运行容器时,可以不用--privileged参数的尽量不用,用--cap-add参数替代。如果必须使用--privileged=true参数的,可以通过在宿主机和容器中执行以下命令将agetty关闭。
shell> systemctl stop getty@tty1.service shell> systemctl mask getty@tty1.service
参考资料:
https://github.com/docker/docker/issues/4040
https://docs.docker.com/engine/reference/run/
docker运行容器后agetty进程cpu占用率100%的更多相关文章
- 获取进程CPU占用率
获取进程CPU占用率 // 时间转换 static __int64 file_time_2_utc(const FILETIME* ftime) { LARGE_INTEGER li; li.LowP ...
- Linux下java进程CPU占用率高分析方法
Linux下java进程CPU占用率高分析方法 在工作当中,肯定会遇到由代码所导致的高CPU耗用以及内存溢出的情况.这种情况发生时,我们怎么去找出原因并解决. 一般解决方法是通过top命令找出消耗资源 ...
- Linux下分析某个进程CPU占用率高的原因
Linux下分析某个进程CPU占用率高的原因 通过top命令找出消耗资源高的线程id,利用strace命令查看该线程所有系统调用 1.top 查到占用cpu高的进程pid 2.查看该pid的线程 ...
- (转)Linux下java进程CPU占用率高-分析方法
Linux下java进程CPU占用率高-分析方法 原文:http://itindex.net/detail/47420-linux-java-%E8%BF%9B%E7%A8%8B?utm_source ...
- Linux下java进程CPU占用率高分析方法(一)
Linux下java进程CPU占用率高分析方法 在工作当中,肯定会遇到由代码所导致的高CPU耗用以及内存溢出的情况.这种情况发生时,我们怎么去找出原因并解决. 一般解决方法是通过top命令找出消耗资源 ...
- Linux下java进程CPU占用率高分析方法(二)
1. 通过 top 命令查看当前系统CPU使用情况,定位CPU使用率超过100%的进程ID:2. 通过 ps aux | grep PID 命令进一步确定具体的线程信息:3. 通过 ps -mp pi ...
- Linux下java进程CPU占用率高-分析方法
今天登陆同事的一台gateway 开始以为hive环境登陆不了了,仔细一看看了下是因为机器很卡,我每次等几秒没登陆就ctrl+c了,看了下是有个java进程cpu:340.4% mem:14.6% ...
- cidaemon.exe进程cpu占用率高及关闭cidaemon.exe进程方法
问题描写叙述: 这段时间机器总是出现一个奇怪的问题:cidaemon.exe进程占用CUP率98%以上,大大影响了电脑的正常使用.资源管理器中出现多个cidaemon.exe进程,强制结束占用cp ...
- WMI获取进程CPU占用率
Monitor % Process CPU Usage (specific process) http://www.tek-tips.com/viewthread.cfm?qid=395765 for ...
随机推荐
- app被Rejected 的各种原因翻译。这个绝对有用
1. Terms and conditions(法律与条款) 1.1 As a developer of applications for the App Store you are bound b ...
- Hdu 4810
2014-05-02 15:53:50 题目连接 2013年南京现场赛的题目,现场的时候,排在我们前面的队伍基本都过了这题,我们后面的队伍也有不少过了这题,唯独我们没有.. 后来是Qingyu Sha ...
- PyCharm切换Python版本
由于代码格式问题,很多情况下需要我们去切换Python版本,那么在当下火爆的PyCharm中是如何切换Python版本的呢? 打开File菜单,选择Settings: 打开Settings窗口后,选择 ...
- 开发一个登录接口(Mysql)
分享一段代码,开发了一个登录接口: 使用Python开发,需要安装flask模块,使用pip intall flask 安装即可,这里使用的数据库是Mysql,所以导入了pymysql模块,代码如下: ...
- thinkphp5.0验证码使用
如果没有安装验证码类,可在composer.json 文件的require里面添加 "topthink/think-captcha":"1.*",然后compo ...
- 关于inflate的第3个参数
关于inf 方法 inflate(int resource, ViewGroup root, boolean attachToRoot) 中,前连个参数都好理解,我比较费解的是第3个参数. 文档中的解 ...
- el-table中加载图片问题
<el-table-column label="头像" width="100"> <template scope="scope&qu ...
- Spring Data JPA 查询结果返回至自定义实体
本人在实际工作中使用Spring Data Jpa框架时,一般查询结果只返回对应的Entity实体.但有时根据实际业务,需要进行一些较复杂的查询,比较棘手.虽然在框架上我们可以使用@Query注解执行 ...
- @atcoder - ARC066F@ Contest with Drinks Hard
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定序列 T1, T2, ... TN,你可以从中选择一些 Ti ...
- Mybatis/Ibatis,数据库操作的返回值
该问题,我百度了下,根本没发现什么有价值的文章:还是看源代码(详见最后附录)中的注释,最有效了!insert,返回值是:新插入行的主键(primary key):需要包含<selectKey&g ...