Search code examples
phpdockerloggingstderr

PHP Docker write to stderr through file


Is it possible to redirect a plain text log file to stderr within a Docker container that is writable by PHP?

I have a PHP application that is writing to a file and we're trying to move it into a Docker container without changing any code. I've tried symlinking but this results in permissions errors.


Solution

  • I ended up finding this solution which uses a fifopipe to pipe the data into stdout.

    # Allow `nobody` user to write to /dev/stderr
    mkfifo -m 600 /tmp/logpipe
    chown nobody:nobody /tmp/logpipe
    cat <> /tmp/logpipe 1>&2 &
    

    https://github.com/moby/moby/issues/6880#issuecomment-344114520