Is there any way I can see the log of a container that has exited?
I can get the container id of the exited container using docker ps -a
but I want to know what happened when it was running.
Is there any way I can see the log of a container that has exited?
I can get the container id of the exited container using docker ps -a
but I want to know what happened when it was running.
You can use below command to copy logs even from an exited container :
Eg:
To directly view the logfile of an exited container in less, scrolled to the end of the file, I use:
run as ./viewLogs.sh CONTAINERNAME
This method has the benefit over
docker logs
based approaches, that the file is directly opened, instead of streamed.sudo is necessary, as the LogPath/File usually is under root-owned
Use
docker logs
. It also works for stopped containers and captures the entire STDOUT and STDERR streams of the container's main process:docker logs --tail=50 <container id>
for the last fifty lines - useful when your container has been running for a long time.