2014-07-05 40 views
3

GDB的問題在Ubuntu 13.04版本泊塢窗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 

這樣做:

[email protected] $ sudo docker run --rm -it --user=root gdb_problem_testing su root -c bash 
[email protected]:/# 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 
[email protected] $ 

不運行程序。 gdb剛起來並退出。在最後一行(su <some_user> -c bash等),請注意,我甚至得到了來自泊塢窗容器啓動並沒有返回到bash提示符(

我一直無法重現這在非泊塢窗環境。

如果我不su <some_user> -c bash而不是使用bash,則不會發生此問題。由於各種原因,必須使用su,主要是因爲這是我發現能夠對碼頭集裝箱中的特定用戶執行ulimits的唯一方式。

爲什麼gdb不能在這種情況下工作?

編輯

複製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

只是爲了表明它是在真實搞亂事情泊塢窗容器su命令,是用bash代替su root -c bash做同樣的事情:

[email protected] $ sudo docker run --rm -it --user=root gdb_problem_testing bash 
[email protected]:/# 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容器中。

+0

出於拼命亂事,我碰巧找到解決辦法。做'sudo -u root su root -c '。我沒有想法爲什麼這應該是不同的,但它是。 gdb將運行,並且所有ulimits仍然適用 –

回答

2

這是由於apparmor。我有一個解決方案,但它需要在每次啓動後應用。

訣竅是告訴apparmor'抱怨'安全違規,而不是阻止他們。這不是最安全的解決方法,我真的想找到一個更好的方式來處理它(例如只允許ptrace和其他任何GDB要求)。

告訴AppArmor的抱怨,你需要從/etc/apparmor.d/docker更改行:

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

到:

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

感謝您的解釋! –

+1

Steven Van Acker提出了一個解決方案[這裏] [1],它可以在引導後倖存下來。 因此,在短期,如果你是在Ubuntu,做這個**在主機上**: '命令和apt-get安裝的AppArmor,utils' 2.啓用: 1.安裝AppArmor的-utils的抱怨器apparmor配置的抱怨模式。 'sudo aa-complain/etc/apparmor。d/docker' 3.在重新引導上述命令持久: '須藤回聲 「AA-抱怨/etc/apparmor.d/docker」 >>的/ etc/rc.local' [1]:HTTPS ://github.com/docker/docker/issues/7276#issuecomment-50436671 –