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?
First of all, to list all running containers, use the docker ps command. Then, with the docker logs command you can list the logs for a particular container. Most of the time you'll end up tailing these logs in real time, or checking the last few logs lines.
Containers are put into exited state by executing the Docker stop command in them. If you want to list only the stopped containers, you can use the --filter option with a parameter called status.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With