I’ll start:
When I was first learning to use Docker, I didn’t realize that most tutorials that include a database don’t configure the database to persist. Imagine my surprise when I couldn’t figure out why the database kept getting wiped!
I’ll start:
When I was first learning to use Docker, I didn’t realize that most tutorials that include a database don’t configure the database to persist. Imagine my surprise when I couldn’t figure out why the database kept getting wiped!
The biggest footgun I encounter every time I set up a raspberry pi or other linux host for a side project is forgetting that Docker doesn’t do log rotation for containers’ logs by default, which results in the service going down and seeing a sweat inducing ENOSPC error when you ssh in to check it out.
You can configure this by creating
/etc/docker/daemon.json
and either setting up log rotation withlog-opts
or using thelocal
logging driver (it defaults tojson
) if you’re not shipping container logs anywhere and just read the logs locally. Thelocal
driver compresses the logs and automatically does log rotation:{ "log-driver": "local", "log-opts": { "max-size": "10m", "max-file": "3" } }
I prefer this method:
{ "log-driver": "syslog", "log-opts": { "tag": "docker.{{.Name}}" } }
This way container logs are forwarded to
/var/log/syslog
, which already contains all other services logs, and has sane rotation rules by default (and it allows rsyslog to manage log forwarding/shipping if needed).Thanks, good to know! I had no idea about the tags. Looks like there’s a lot more variables available.
I just reread the docs on the log drivers - they mentioned that as of docker 20.x local logs now work with all drivers as it buffers the logs locally as well. I think this is probably why I hadn’t explored the other drivers before - couldn’t use docker-compose logs.
TIL. Thank you! (Now I will ssh into all my VPSes and set this up!)
(cool username btw)