Docker Community Forums

Share and learn in the Docker community.

Java leaves zombie processes


(Incapturebuild) #1

I have a docker image which executes a shell script that runs a series of Java programs.
I am finding that the script does not complete; on examination I find that one of the Java executables exited but is a zombie - the caller failed to reap the exit status.

I’ve simplified the scripts to a bare minimum and it’s consistently reproducible.

The script that’s executed when the container is:

#!/bin/bash
for f in 1 2 3 4 5 6 7 8 9 10
do
echo do $f
/tmp/bar
done

/tmp/bar is very simple too:

#!/bin/bash
java >> /tmp/j.out 2>&1

On startup the container never completes. It’s not consistent; the log may show that the first Java invocation was successful but it never gets through all 10. The same happens if I log on to the container using docker exec and run the script manually.

ps shows a java zombie, although what’s interesting is that unlike a normal Unix zombie the TIME field continues to increase.

UID PID PPID C STIME TTY TIME CMD
root 1 0 0 01:23 ? 00:00:00 /bin/bash /tmp/feat.sh
root 17 1 0 01:23 ? 00:00:00 /bin/bash /tmp/bar
root 18 17 99 01:23 ? 00:06:13 [java]
root 28 0 0 01:23 ? 00:00:00 sh
root 40 28 0 01:29 ? 00:00:00 ps -ef

Any advice?


(Frank) #2

How did you start the container?


(Incapturebuild) #3

docker run imagename from the quick start terminal.
Also ran it from kinematic - same result


(Frank) #4

Ok I’m still learning docker but since you asked for “any advice” here it is lol

You probably need the -d option for detached or -i for interactive (depending on how you want to run it)? I think I recall with no options it runs and quits/dies. If your stuff takes some time (which java always does) I’m thinking the container ends thus the zombie but I am guessing. So it’s “any Ideas” lol


(Incapturebuild) #5

I read https://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/ and tried using their container.

I ran docker run --rm -t -i phusion/baseimage /sbin/my_init – bash -l

I connected to the container using docker exec, installed Java using apt-get install default-jre and executed java; no arguments, just called java from the shell. I got a zombie - never got the shell prompt back.

On closer examination I realized that the apt-get install hadn’t completed either

 root        40    33  0 18:45 ?        00:00:00 bash
 root        72    40  0 18:46 ?        00:00:22 apt-get install default-jre
 root      3620    72  0 18:51 pts/0    00:00:00 /usr/bin/dpkg --status-fd 21 --configure libelf1:amd64 libsystemd-daemon0:amd64 libapparmor1
 root      4656  3620  0 18:51 pts/0    00:00:00 /bin/bash /var/lib/dpkg/info/ca-certificates-java.postinst configure
 root      4670  4656 56 18:51 pts/0    00:20:25 [java] <defunct>

(Incapturebuild) #6

If it matters I’m running on a Mac, El Capitan, with VirtualBox 5.0.10 r104061 running boot2docker version 1.9.1 build a34a1d5 - the virtual machine has 4Gb RAM


(Ryan R Sundberg) #7

Hey there, I experienced the same problem (on multiple different images), but all of them were using phusion/baseimage.

It looks like the fix is included in the 0.9.18 release:

https://github.com/phusion/baseimage-docker/commit/7425da28255b4b1a88527ccb7897285df7aea967

https://github.com/phusion/baseimage-docker/issues/151

(docker forums not letting me post the link)