Hey everyone! I'm currently running a PHP app in a Docker container and I've set up my source code to mount from the host like this: `volumes: - ./src:/var/www/html`. Within the app, PHP writes metrics and logs to a `log/` directory. The issue I'm facing is that if I don't manually create the `log/` folder and set the permissions to `chmod 777`, I run into permission errors because the app can't write logs. I'm looking for guidance on a few things: 1. What are the best practices for managing log directories and files in this setup? 2. Is using `chmod 777` safe, or is there a better way to handle permissions? 3. Are there any recommended patterns for Docker logging, especially with bind mounts? Currently, my workaround involves manually creating the `log/` folder and files on the host with those permissions, but it feels a bit hacky. Any advice from those who've navigated this successfully would be greatly appreciated! Thanks!
1 Answer
Instead of writing logs to files, try writing them to stdout/stderr. Docker captures these outputs automatically, and you can view them using the `docker logs` command. This would also help you avoid those permission issues with bind mounts altogether. Check out the Docker logging documentation for more details!
Thanks! I think switching my PHP logs to stdout/stderr will definitely help with the permission issues. What about metrics though? I was logging those to a metrics file — is that still a good practice in containers, or is there a better way to handle metrics?