2

I am running a jar package within a container by docker. I spot when there is database connect timeout issue or kafka connect issue, the container will fail. However, I will be fine if I print java error log to console or log file. Anyone can clarify the logic to define a container as failed/error, Thanks!

James Pei
  • 151
  • 2
  • 11

2 Answers2

1

Well there is no such thing as failed/errorneus container. Docker image can have default ENTRYPOIN or CMD which executes as docker container is started but when command ends docker lifecycle ends as well.

I assume you run some server app in docker container which serves forever which makes one think that docker images all run without stopping. Your docker which should always run stops after your app crashes, you can see the details in docker logs if your didn't run it with --rm option. Try docker ps -a to see your container with exited status and see execution logs or extract files from it's filesystem to debug what went wrong.

makozaki
  • 3,772
  • 4
  • 23
  • 47
0

To the extent Docker has this concept at all, it follows normal Unix semantics. The container runs a single process, and when that process exits, the container exits too. If the process exits with a status code of 0 it is "successful" and if it exits with any other status code it "fails".

In the context of a Java container, Is there a complete List of JVM exit codes asserts that a JVM will always exit with status code 0 ("success") even if the program terminates with an uncaught exception; it will only return "failure" if the JVM itself fails in some way.

The most significant place this can matter is around a restart policy. If you start your container with docker run --restart on-failure, an uncaught exception won't be considered "failure" and your container won't restart.

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • Thanks David, my current restart policy is “always”, what do you think the best practice in product? – James Pei Apr 10 '20 at 02:20
  • Kubernetes pods default to a similar "immediately restart a container if it exits for any reason" policy, that's probably fine in pure-Docker setups too. – David Maze Apr 10 '20 at 10:14