45

I have a Docker container that contains a JVM process. When the process ends the container completes and stops.

While thankfully rare, my JVM can go legs-up suddenly with a hard-failure, e.g. OutOfMemoryError. When this happens my container just stops, like a normal JVM exit.

I can have distributed logging, etc., for normal JVM logging, but in this hard-fail case I want to know the JVM's dying words, which are typically uttered on stderr.

Is there a way to know why my container stopped, look around in logs, stderr, or something along these lines?

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Greg
  • 10,696
  • 22
  • 68
  • 98
  • 4
    What do you see in `docker logs` for the stopped container? Have you tried subscribing to events? The `docker` daemon exposes an API: https://docs.docker.com/reference/api/docker_remote_api_v1.16/ – Andy Jan 14 '15 at 23:01
  • 1
    The container is gone, ie its not there when I do docker ps, so I dont know how to get logs on it. I'll check into the events api. I have monitoring so I do know the jvm died... I just dont know those last messages output to stderr, which are not logged (in the case of OOM, the logger may not even work) – Greg Jan 16 '15 at 03:12
  • 28
    You can run the docker logs [ContainerName] or [ContainerID] command even on stopped containers. You can see them with docker ps -a – Usman Ismail Jan 16 '15 at 14:38
  • Can you please mark the answer as accepted? – mikemaccana Jan 26 '21 at 16:57

1 Answers1

60

You can run the docker logs [ContainerName] or docker logs [ContainerID] command even on stopped containers. You can see them with docker ps -a.

Source: the comment of Usman Ismail above: this is just a way to convert his comment into a proper answer.

Stunner
  • 12,025
  • 12
  • 86
  • 145
Cristan
  • 12,083
  • 7
  • 65
  • 69