symfony docker-compose output log to host

Viewed 134

I am setting up a Symfony 6/Next js app with docker-compose and would like to have the logs from Monolog that in Symfony are output to /var/log/ show on a host file within the app code, so that I can easily review it with VSCode instead of the awkward process of opening a shell.

Note that the logs are correctly output with the container, which is fine.

So I have attempted to create a bind mount, but either it just does not work or it throws an error with docker-compose up.

Something like:

services:
  php:
    build:
    context: ./api
    target: api_platform_php
    depends_on:
      - database
    restart: unless-stopped
    volumes:
       - php_socket:/var/run/php
       - ./api/var/log:/srv/api/var/log ***HERE***

In this specific instance it will error: setfacl: var/log: Not supported

I did find a number of related questions on SO, including this one, but they either concern overall docker logs or are not directly applicable.

1 Answers

Not what you asked, but its common practice to pipe the logs to the container:

Monolog config: path: "php://stderr"

then you can use docker-compose logs -f --tail="all" php

from outside the container

Related