Tips for developing with Docker.
Write critical logs outside the container
You are developing an app, so it will go wrong. It will go wrong a lot, that’s fine. But at the beginning you will have a cycle that goes like this: container starts up, container starts your app, app fails and exits, container stops. What went wrong with your app? You’ve got no idea.
Because the container died, you lost the logs and if you start the container up again, the same thing happens.
If you store the critical logs of your app outside your container, then you can see the problems after it exits. If you use a process runner like supervisord then you’ll find that docker logs contains your process runner.
You can do a few things here, like move your logs into the process runner logs, or just write your logs to a location that allows you to save them. There’s lots of ways to do that, but since we use supervisord and docker-compose, for us its a matter of making sure supervisord writes its logs out to a volume.
See also part 1.