Retrieving container logs
It is a best practice for any good application to generate some logging information that developers and operators alike can use to find out what the application is doing at a given time, and whether there are any problems to help to pinpoint the root cause of the issue.
When running inside a container, the application should preferably output the log items to STDOUT
and STDERR
and not into a file. If the logging output is directed to STDOUT
and STDERR
, then Docker can collect this information and keep it ready for consumption by a user or any other external system:
- Run a trivia container in
detach
mode:$ docker container run --detach \ --name trivia fundamentalsofdocker/trivia:ed2
Let it run for a minute or so so that it has time to generate a few trivia questions.
- To access the logs of a given container, we can use the
docker container logs
command. If, for example, we want to retrieve the logs of ourtrivia...