Is there any way to have the process launched by my docker run
command launch under the same process tree as the program executing the docker run
command?
No, all the processes managed by the Docker Engine are children of the Docker Engine (daemon). For example:
docker run supertest2014/nyan
(another shell on the same machine)
ps faux
...
root 762 2.5 3.3 462068 16676 ? Ssl 19:07 0:10 /usr/bin/docker -d
root 1563 0.0 0.1 4444 648 ? Ss 19:13 0:00 \_ /bin/sh -c nyancat
root 1573 0.2 0.0 4228 352 ? S 19:13 0:00 \_ nyancat
...
There you can see the docker
daemon running (docker -d
) and the CMD
in the nyan container was /bin/sh -c nyancat
which then launched nyancat
.
You can however have your container share the process ID space and IPC namespace with another process, even the host. For instance, if you normally run a container, it can only see the processes running inside the container:
root@processtree:~# docker run -it --name containerpid supertest2014/nyan
<another window>
root@processtree:~# docker exec -it containerpid /bin/bash
<note this is the WHOLE process tree>
root@355f839c31bc:/# ps faux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 11 0.5 0.3 18132 1840 ? Ss 23:25 0:00 /bin/bash
root 19 0.0 0.2 15564 1092 ? R+ 23:25 0:00 \_ ps faux
root 1 0.0 0.1 4444 648 ? Ss 23:13 0:00 /bin/sh -c nyancat
root 10 0.2 0.0 4228 352 ? S 23:13 0:01 nyancat
But if you run with --pid host
then the process tree shows everything on the host:
...
root@processtree:~# docker run -it --name hostpid --pid host supertest2014/nyan
<another window>
root@processtree:~# docker exec -it hostpid /bin/bash
<note this is a partial process tree, there was a lot more going on!>
root@processtree:~# ps faux
root 1 0.0 0.5 33500 2820 ? Ss 23:07 0:01 /sbin/init
root 356 0.0 0.1 19472 648 ? S 23:07 0:00 upstart-udev-bridge --daemon
root 361 0.0 0.3 51360 1632 ? Ss 23:07 0:00 /lib/systemd/systemd-udevd --daemon
root 503 0.0 0.1 15256 652 ? S 23:07 0:00 upstart-socket-bridge --daemon
102 721 0.0 0.2 39224 1256 ? Ss 23:07 0:00 dbus-daemon --system --fork
root 762 1.4 3.6 700744 18156 ? Ssl 23:07 0:19 /usr/bin/docker -d
root 1563 0.0 0.1 4444 648 ? Ss 23:13 0:00 \_ /bin/sh -c nyancat
root 1573 0.2 0.0 4228 352 ? S 23:13 0:02 | \_ nyancat
root 2040 0.0 0.1 4444 652 ? Ss+ 23:23 0:00 \_ /bin/sh -c nyancat
root 2048 0.2 0.0 4228 360 ? S+ 23:23 0:00 | \_ nyancat
root 2183 0.5 0.3 18152 1848 ? Ss 23:28 0:00 \_ /bin/bash
root 2190 0.0 0.2 15720 1216 ? R+ 23:28 0:00 \_ ps faux
root 819 0.0 0.3 43448 1756 ? Ss 23:07 0:00 /lib/systemd/systemd-logind
syslog 833 0.0 0.3 255840 1612 ? Ssl 23:07 0:00 rsyslogd
root 863 0.0 0.1 15272 628 ? S 23:07 0:00 upstart-file-bridge --daemon
root 937 0.0 0.1 15816 956 ? Ss+ 23:07 0:00 /sbin/getty -8 38400 tty4
root 941 0.0 0.1 15816 952 ? Ss+ 23:07 0:00 /sbin/getty -8 38400 tty5
root 950 0.0 0.1 15816 960 ? Ss+ 23:07 0:00 /sbin/getty -8 38400 tty2
root 951 0.0 0.1 15816 960 ? Ss+ 23:07 0:00 /sbin/getty -8 38400 tty3
root 957 0.0 0.1 15816 956 ? Ss+ 23:07 0:00 /sbin/getty -8 38400 tty6
root 987 0.0 0.6 61364 3068 ? Ss 23:07 0:00 /usr/sbin/sshd -D
...