I have a Docker container which has crashed due to a bug in the containerized application.
The restart policy was set to unless-stopped
, which was causing the container to start, immediatly crash, and then restart again.
I changes the restart policy using docker container update --restart=no <container-name>
.
I would like to download (copy) the log file from the container to the host machine so that I can inspect it to find out what went wrong.
If the container were running, I would simply be able to run docker exec -it <container-name> bash
to start a bash
session within the container. I would then be able to navigate the file system, find the log file, and either inspect it within the container or copy it from the container with docker cp
.
However, the container is not running, and cannot be started because it will immediatly crash.
What are my options in this situation?
3
Answers
a) In your dockerfile, you could change your entrypoint to:
b) Or
Commit the stopped container:
Start/run with a different entry point:
c) Or you could try docker debug: https://docs.docker.com/reference/cli/docker/debug/
There are multiple solutions for that:
docker logs CONTAINER
shows what was going on inside of the container.change the entry point to
sh
orbash
and debug it:Replace
path/to/logfile
with the actual path to the log file inside the container andpath/to/host/directory
with the destination on your host machine.Run the image by:
json-file
log driver. For container IDTo copy or view logs: