Every source I read is saying the log locations are here:
/var/lib/docker/containers/{container-id}/{container-id}-json.log.
But when I check mine, all I see is /var/lib/docker/containers/{container-id}/
and when I ls
that, it shows:
checkpoints
config.v2.json
hostconfig.json
hostname
hosts
resolv.conf
resolv.conf.hash
secrets
shm
No logs at all.
What are other possible log locations of the containers?
Btw, host is Vagrant CentOS.
2
Answers
For those who care:
I may be running an old docker engine which did not use
json-file
logging driver as default. I tried changing the default driver tojson-file
but that resulted to cascading errors that needed fixing, one after another.So I decided to F it and completely reinstall the docker engine and rebuild the images. Guess what, the
/var/lib/docker/containers/{container-id}/{container-id}-json.log.
files magically appeared.Note: You may need to rebuild all images that you want to use this logging format.
Rhetorical question: why would you need to know that?
You can access a container’s logs by calling
docker container logs <container_id>
, anddocker-compose logs <service>
in compose. These commands dump the contents of the logs to stdout where you can process them using normal pipes. The containers themselves also send their logs (by default) to stdout, so you can pipe them directly to a log-shipping service or anything else that takes your fancy.The location of the log history files is an implementation detail that changes across platforms and is configurable per daemon and is even configurable per container. Using the CLI (or REST API) is the most platform-independent way to access the logs and it saves you having to find them.