title: How do you get debugging symbols working in linux perf tool inside Docker containers?
body: <p>I am using Docker containers based on the "ubuntu" tag and cannot get linux perf tool to display debugging symbols.</p>
  
  <p>Here is what I'm doing to demonstrate the problem.</p>
  
  <p>First I start a container, here with an interactive shell.</p>
  
  <pre><code>$ docker run -t -i ubuntu:14.04 /bin/bash
  </code></pre>
  
  <p>Then from the container prompt I install linux perf tool.</p>
  
  <pre><code>$ apt-get update
  $ apt-get install -y linux-tools-common linux-tools-generic linux-tools-`uname -r`
  </code></pre>
  
  <p>I can now use the <code>perf</code> tool. My kernel is <code>3.16.0-77-generic</code>.</p>
  
  <p>Now I'll install <code>gcc</code>, compile a test program, and try to run it under <code>perf record</code>.</p>
  
  <pre><code>$ apt-get install -y gcc
  </code></pre>
  
  <p>I paste in the test program into <code>test.c</code>:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int function(int i) {
      int j;
      for(j = 2; j &lt;= i / 2; j++) {
          if (i % j == 0) {
              return 0;
          }
      }
      return 1;
  }
  
  int main() {
      int i;
      for(i = 2; i &lt; 100000; i++) {
          if(function(i)) {
              printf("%d\n", i);
          }
      }
  }
  </code></pre>
  
  <p>Then compile, run, and report:</p>
  
  <pre><code>$ gcc -g -O0 test.c &amp;&amp; perf record ./a.out &amp;&amp; perf report
  </code></pre>
  
  <p>The output looks something like this:</p>
  
  <pre><code>  72.38%  a.out  a.out              [.] 0x0000000000000544
     8.37%  a.out  a.out              [.] 0x000000000000055a
     8.30%  a.out  a.out              [.] 0x000000000000053d
     7.81%  a.out  a.out              [.] 0x0000000000000551
     0.40%  a.out  a.out              [.] 0x0000000000000540
  </code></pre>
  
  <p>This does not have symbols, even though the executable does have symbol information.</p>
  
  <p>Doing the same general steps outside the container works fine, and shows something like this:</p>
  
  <pre><code>96.96%  a.out  a.out             [.] function 
  0.35%  a.out  libc-2.19.so       [.] _IO_file_xsputn@@GLIBC_2.2.5
  0.14%  a.out  [kernel.kallsyms]  [k] update_curr
  0.12%  a.out  [kernel.kallsyms]  [k] update_cfs_shares
  0.11%  a.out  [kernel.kallsyms]  [k] _raw_spin_lock_irqsave                 
  </code></pre>
  
  <p>In the host system I have already turned on kernel symbols by becoming root and doing:</p>
  
  <pre><code>$ echo 0 &gt; /proc/sys/kernel/kptr_restrict 
  </code></pre>
  
  <p>How do I get the containerized version to work properly and show debugging symbols?</p>