Docker中的GDB问题

使用Docker version 1.1.0, build 79812e3版本Docker version 1.1.0, build 79812e3在Ubuntu 13.04上Docker version 1.1.0, build 79812e3 ,并使用由以下项创build的Docker version 1.1.0, build 79812e3容器:

 # docker build -t gdb_problem_testing - < THIS_FILE FROM ubuntu RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list RUN apt-get update RUN apt-get install -y build-essential gdb 

这样做:

 user@host $ sudo docker run --rm -it --user=root gdb_problem_testing su root -c bash root@690396061e81:/# cat <<EOF > test.c && gcc -ggdb test.c -o test && gdb -ex run test > #include <stdio.h> > > int main(int argc, char **argv) { > printf("Hello\n!"); > } > EOF GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02 Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". For bug reporting instructions, please see: <http://bugs.launchpad.net/gdb-linaro/>... Reading symbols from /test...done. Starting program: /test user@host $ 

不运行程序。 gdb刚起来,退出。 注意最后一行,我甚至从Docker容器启动,并没有返回到bash提示符(

我一直无法在非docker环境( su <some_user> -c bash等)中重现这一点。

如果我不su <some_user> -c bash ,而是只使用bash则不会发生此问题。 出于各种原因,必须使用su ,主要是因为它是唯一的方法,我发现可以强制docker集装箱中的特定用户ulimits。

gdb为什么不在这种情况下工作?

编辑

在docker容器中运行的copy-pastable命令:

 cat <<EOF > test.c && gcc -ggdb test.c -o test && gdb -ex run test #include <stdio.h> int main(int argc, char **argv) { printf("Hello\n!"); } EOF 

UPDATE

只是为了表明它是一个docker容器中的su命令,搞乱了一切,下面是用bash代替su root -c bash做同样的事情的输出:

 user@host $ sudo docker run --rm -it --user=root gdb_problem_testing bash root@ce1581184f7a:/# cat <<EOF > test.c && gcc -ggdb test.c -o test && gdb -ex run test > #include <stdio.h> > > int main(int argc, char **argv) { > printf("Hello\n!"); > } > EOF GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02 Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". For bug reporting instructions, please see: <http://bugs.launchpad.net/gdb-linaro/>... Reading symbols from /test...done. Starting program: /test warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000 Hello ![Inferior 1 (process 17) exited with code 07] (gdb) 

注意程序实际上是如何运行的(打印出“Hello”),我留在gdb和Docker容器中。

这是由于apparmor。 我有一个解决scheme,但它需要在每次启动后应用。

诀窍是告诉他们“抱怨”安全违规行为,而不是阻止他们。 这不是最安全的解决方法,我真的想find一个更好的方式来处理它(就像只允许ptrace和其他任何GDB要求)。

要告诉apparmor抱怨,你需要改变/etc/apparmor.d/docker中的行:

 profile docker-default flags=(attach_disconnected,mediate_deleted) { 

至:

 profile docker-default flags=(attach_disconnected,mediate_deleted,complain) {