Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know why a Docker container stopped?

Tags:

docker

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?

like image 214
Greg Avatar asked Jan 14 '15 18:01

Greg


People also ask

How can I see the logs of a docker container?

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.

How do I find out if a docker container is stopped?

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.


1 Answers

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.

like image 85
Cristan Avatar answered Oct 06 '22 04:10

Cristan