【发布时间】:2014-08-26 11:44:06
【问题描述】:
在 Ubuntu 13.04 上使用 docker 版本 Docker version 1.1.0, build 79812e3,并使用以下创建的 docker 容器:
# 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 容器中的特定用户强制执行 ulimit 的唯一方法。
为什么 gdb 在这种情况下不起作用??
编辑
copy-pastable 命令在 docker 容器中运行:
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
更新
只是为了表明是 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 容器中。
【问题讨论】:
-
出于拼命尝试随机的事情,我碰巧找到了解决这个问题的方法。做
sudo -u root su root -c <cmd>。我不知道为什么会有所不同,但确实如此。 gdb 将运行,所有 ulimits 仍然适用