Java process in Docker container does not exit end of main ()

I have a jar jar command and I am invoking it from within python using Popen. I am glad that I am doing it right, and I have many reasons why I am doing it this way (this is not very good, but this is what it is).

When I run Java locally, it works fine (JRE 1.8), when I run python locally, which calls Java, it works fine. When I run it inside the docker container, it just hangs - the python is on process.communicate (), and when I do docker exec it just doesn't return (the output from the command is exactly what I expect).

What I found is that if theres explicitly System.exit(0); at the end of Java, then the Java process does not end when launched inside the docker container - it just hangs, at the point of all processing.

To test this, I made a 5-line Hello World application (in System.exit I will either comment on whether this works or not)

 public class Hello { public static void main(String[] args) { System.out.println("Heellllooo"); // System.exit(0); } } 

I linked this to Jar and placed it in the folder where the "real" bank sits and runs.

Without system.exit() process freezes. With him he comes out clean. In both cases, "Heelllloooo" is printed.

Other random facts that can help diagnose the command I use to test this: (popen in python is much more complicated with the arguments I pass to Java).

 docker exec [tag] java -jar libs/Hello.jar 

If I do this:

 docker exec [tag] java -version 

he returns immediately with version information.

I am running Mac, so this works inside the boot2docker Ubuntu vm boot machine dock. Other people running the same docker files on Debian and Ubuntu machines have no problems at all.

I don't think the problem is with Python because the symptoms are present when running from exec (therefore, I don't put it in python).

My question is: Why does the Java process not terminate when the main function returns?

To be clear, I do not want to know how to kill a process (I know how to do it), I want to know why the process is not returning. (and this seems like a specific java / docker thing).

+7
java docker boot2docker macos
source share
1 answer

Unfortunately, this looks like the case https://github.com/docker/docker/issues/18180 , which is still (at least from 2015 to 18-18) unresolved (besides downgrading the kernel or changing application code).

+2
source share

All Articles