如何调试 dockerized self-detaching 程序?

How to debug dockerized self-detaching program?

我正在为 Debian-like 发行版编写 Docker images for maintainers 个包。这些镜像是从各自 Debian-like 发行版的官方镜像中通过添加维护所需的包派生而来的,并以一些有用的挂载卷开始,因此各种配置项是从用户环境中获取的,而不是保存在容器中.

当我从该图像开始 shell 并执行 apt-src build 来准备一个包时,操作正常开始,但容器和tty 莫名其妙地下降。使用 docker ps -a 检查容器的状态表明它 Exited (0)。这很奇怪,因为这意味着某些东西导致 shell 在它的子命令 运行s.

退出时退出

哪些步骤可以帮助我调试这种奇怪的行为,弄清楚这里发生了什么,并最终修复它?


容器运行命令

这是我启动容器的方式:

docker run\
    --interactive=true\
    --tty=true\
    --rm=false\
    --volume "${maintainer_pkgdir}:${maintainer_docker_pkgdir}"\
    --volume "${maintainer_srcdir}:${maintainer_docker_srcdir}"\
    --volume "${maintainer_confdir}:${maintainer_docker_confdir}"\
    "${maintainer_repository}/${maintainer_image}"

Session成绩单

session由apt-src install bmakeapt-src build bmake两个命令组成:

% apt-src install bmake
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Need to get 544 kB of source archives.
Get:1 http://ftp.debian.org/debian/ unstable/main bmake 20140620-3 (dsc) [1785 B]
Get:2 http://ftp.debian.org/debian/ unstable/main bmake 20140620-3 (tar) [509 kB]
Get:3 http://ftp.debian.org/debian/ unstable/main bmake 20140620-3 (diff) [33.0 kB]
Fetched 544 kB in 0s (681 kB/s)
gpgv: Signature made Tue Sep 16 20:22:02 2014 UTC using RSA key ID 1A2D268D
gpgv: Can't check signature: public key not found
dpkg-source: warning: failed to verify signature on ./bmake_20140620-3.dsc
dpkg-source: info: extracting bmake in bmake-20140620
dpkg-source: info: unpacking bmake_20140620.orig.tar.gz
dpkg-source: info: unpacking bmake_20140620-3.debian.tar.xz
dpkg-source: info: applying 100_makefile.boot.diff
dpkg-source: info: applying 140_multiarch.diff
dpkg-source: info: applying 160_manpage.diff
dpkg-source: info: applying 180_bmake_path_max.diff
% apt-src build bmake
I: Building in /home/anvil/bmake-20140620 ..
dpkg-buildpackage: source package bmake
dpkg-buildpackage: source version 20140620-3
dpkg-buildpackage: source changed by Andrew Shadura <andrewsh@debian.org>
dpkg-buildpackage: host architecture amd64
 dpkg-source --before-build bmake-20140620
 fakeroot debian/rules clean
dh clean --with=autoreconf
   dh_testdir
   debian/rules override_dh_auto_clean
make[1]: Entering directory `/home/anvil/bmake-20140620'
/usr/bin/make -f Makefile.boot clean
make[2]: Entering directory `/home/anvil/bmake-20140620'
rm -f arch.o buf.o compat.o cond.o dir.o for.o hash.o job.o main.o make.o make_malloc.o parse.o str.o strlist.o suff.o targ.o trace.o var.o util.o meta.o strlcpy.o lst.lib/lstAppend.o lst.lib/lstAtEnd.o lst.lib/lstAtFront.o lst.lib/lstClose.o lst.lib/lstConcat.o lst.lib/lstDatum.o lst.lib/lstDeQueue.o lst.lib/lstDestroy.o lst.lib/lstDupl.o lst.lib/lstEnQueue.o lst.lib/lstFind.o lst.lib/lstFindFrom.o lst.lib/lstFirst.o lst.lib/lstForEach.o lst.lib/lstForEachFrom.o lst.lib/lstInit.o lst.lib/lstInsert.o lst.lib/lstIsAtEnd.o lst.lib/lstIsEmpty.o lst.lib/lstLast.o lst.lib/lstMember.o lst.lib/lstNext.o lst.lib/lstOpen.o lst.lib/lstRemove.o lst.lib/lstReplace.o lst.lib/lstSucc.o lst.lib/lstPrev.o  bmake
make[2]: Leaving directory `/home/anvil/bmake-20140620'
make[1]: Leaving directory `/home/anvil/bmake-20140620'
   dh_autoreconf_clean
   dh_clean
 debian/rules build

将程序附加到 tty 似乎是一个不完全可靠的操作,这意味着它仅在程序使用 tty 合理。

程序 su 因滥用 tty 连接而臭名昭著,因此与其解决问题不如避免使用更容易su 或滥用它所连接的 tty 的任何其他程序。