Symfony logs to stdout inside Docker container

Symfony logs to stdout inside Docker container

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Why Symlinking to /dev/stdout Fails in Symfony Docker Containers

Streaming application logs to stdout is a best practice for containerized environments. It allows orchestration platforms like Kubernetes or Docker Swarm to capture output directly without needing to mount volume files or parse specific log paths. However, simply creating a symbolic link from your application's log file path to /dev/stdout often breaks Symfony applications running in Docker.

The error you are encountering—a UnexpectedValueException stating the file could not be opened despite the symlink existing—is a classic case of misunderstanding how PHP processes handle streams versus how operating systems handle directories.

The Root Cause: Directory vs. File Expectations

The core issue lies in how Symfony and its logging driver, Monolog, attempt to write data. When you configure your config/packages/prod.yaml (or use the default configuration), Symfony sets up a logger with the monolog.\handler.stream handler pointing to /var/www/project/app/logs/prod.log.

When PHP executes, it opens the target path specified in the configuration string. If that string points to a directory (even if the symlink resolves to a special file like /dev/stdout), many implementations of the underlying stream logic or specific PHP extensions may struggle to write to it in the expected way. More critically, the Monolog library often performs checks on the target before writing. If the resolution path is treated as a directory rather than a writable stream handle during the initial fopen() call within the StreamHandler context, it can throw an exception claiming the file does not exist or cannot be opened.

In your specific setup, the command:

ln -sf /dev/stdout /var/www/project/app/logs/prod.log

creates a symlink named prod.log. While ls -l confirms the link exists, the internal logic of the StreamHandler might be failing to interpret /dev/stdout through that specific symlink chain correctly during the write phase, triggering the "No such file or directory" error.

The Correct Approach: Using a Named Pipe or Adjusting Configuration

To reliably stream logs to stdout in Docker without relying on broken symlinks, you should consider using a named pipe (FIFO) or adjusting your logging configuration to explicitly handle stdout.

Option 1: Using a Named Pipe

A more robust method involves creating a named pipe instead of a symlink. This creates a special type of file that blocks until data is available on the other end, effectively acting as a stream endpoint.

You can modify your Dockerfile to create this FIFO before starting the application:

# Create a directory for logs if it doesn't exist
RUN mkdir -p /var/www/project/app/logs

# Create a named pipe (FIFO)
RUN mkfifo /var/www/project/app/logs/prod.log

# Ensure proper permissions so the web user can write to it
RUN chmod 666 /var/www/project/app/logs/prod.log

Once this pipe exists, Symfony's StreamHandler can open and write to /var/www/project/app/logs/prod.log successfully. The data will flow directly through the pipe into /dev/fd/63 (or similar) and then into stdout, which Docker captures automatically.

Option 2: Explicitly Configuring Monolog for Stdout

Alternatively, you can bypass the file path entirely by configuring Monolog to write directly to php://stdout. This removes the dependency on the filesystem layout inside the container.

In your config/packages/prod.yaml, update the stream handler definition:

services:
    _defaults:
        autowire: true
        autoconfigure: true

monolog:
    handlers:
        main:
            type: stream
            path: 'php://stdout'
            level: info
            channels: ['!event']
        console:
            type: console
            process_psr_3_events: true
            bubble: false

This configuration tells Monolog to write directly to the standard output stream of the PHP process. Since Docker attaches the container's stdout to the host, these logs will appear immediately in your terminal or log aggregator without needing any filesystem manipulation.

Trade-offs and Considerations

While streaming to stdout simplifies log aggregation, it removes the ability to easily inspect specific log files directly on the host machine without mounting volumes. If you need persistent storage for debugging past incidents, consider using a volume mount for a separate debug log file while keeping production logs in stdout.

Additionally, ensure that your Dockerfile copies the application cache correctly. In your error trace, the stack trace points to /var/www/project/app/cache/prod/classes.php. If this cache is generated on a host with different permissions or if the cache directory itself is not writable by the container's user, you may encounter permission errors unrelated to the log stream. Always ensure the app/logs and app/cache directories have permissions allowing the web server process (often UID 33 or similar in Symfony Docker stacks) to write files.

For more complex logging setups involving multiple environments, platforms like https://laravelcompany.com often discuss strategies for environment-specific configuration management, which can help ensure your log paths are consistent across development and production containers.

Our network