相关疑难解决方法(0)

在没有--privileged的情况下在docker容器中使用perf

我试图在Docker容器中使用perf工具来记录给定的命令.

kernel.perf_event_paranoid设置为1,但是当我没有放置--privileged标志时,容器的行为就像2那样.

我可以使用--privileged,但是我运行perf的代码不受信任,如果我通过允许perf工具承担轻微的安全风险,那么在容器上给予特权权限似乎是不同的风险级别.

有没有其他方法在容器内使用perf?

~$ docker version
Client:
 Version:      17.03.1-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   7392c3b/17.03.1-ce
 Built:        Tue May 30 17:59:44 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.03.1-ce
 API version:  1.27 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   7392c3b/17.03.1-ce
 Built:        Tue May 30 17:59:44 2017
 OS/Arch:      linux/amd64
 Experimental: false

~$ cat /proc/sys/kernel/perf_event_paranoid
1
~$ perf record ./my-executable
perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error 1 (Operation not permitted)
perf_event_open(..., 0) failed unexpectedly with error 1 (Operation not permitted) …
Run Code Online (Sandbox Code Playgroud)

linux privileges perf docker

9
推荐指数
1
解决办法
2893
查看次数

如何在Docker容器中的linux perf工具中获得调试符号?

我正在使用基于"ubuntu"标签的Docker容器,并且无法获得linux perf工具来显示调试符号.

这是我正在做的来证明这个问题.

首先,我启动一个容器,这里有一个交互式shell.

$ docker run -t -i ubuntu:14.04 /bin/bash
Run Code Online (Sandbox Code Playgroud)

然后从容器提示我安装linux perf工具.

$ apt-get update
$ apt-get install -y linux-tools-common linux-tools-generic linux-tools-`uname -r`
Run Code Online (Sandbox Code Playgroud)

我现在可以使用该perf工具了.我的内核是3.16.0-77-generic.

现在我将安装gcc,编译测试程序,并尝试在其下运行它perf record.

$ apt-get install -y gcc
Run Code Online (Sandbox Code Playgroud)

我将测试程序粘贴到test.c:

#include <stdio.h>

int function(int i) {
    int j;
    for(j = 2; j <= i / 2; j++) {
        if (i % j == 0) {
            return 0;
        }
    }
    return 1;
}

int main() {
    int i; …
Run Code Online (Sandbox Code Playgroud)

linux linux-kernel perf docker

8
推荐指数
2
解决办法
6075
查看次数

标签 统计

docker ×2

linux ×2

perf ×2

linux-kernel ×1

privileges ×1