[Solved] Docker League\Flysystem\UnableToCreateDirectory Unable to create a directory at /var/www/storage/app/public/

Updated: 13th April 2025
Tags: laravel docker

If you use Docker and use some volume attached to (for real, use some s3 compatible stuff for storing files) you can get this error.

League\Flysystem\UnableToCreateDirectory
Unable to create a directory at /var/www/storage/app/public/

Assuming that you tried different ways to give permissions in Dockerfile like

RUN chown -R nginx:nginx /var/www/storage/
RUN ln -s /var/www/storage/app/public/ /var/www/public/storage

or even add some RUN chmod -R 777 /var/www/storage and it still doesn’t work.

Solution

  1. Create docker/entrypoint.sh
  2. Replace chown, ln, chmod commands from Dockerfile with run entrypoint.sh.

docker/entrypoint.sh file:

#!/bin/sh

# Set correct permissions
chown -R nginx:nginx /var/www/storage /var/www/bootstrap/cache
chmod -R 775 /var/www/storage /var/www/bootstrap/cache

# Create storage symlink if missing
[ -L /var/www/public/storage ] || /usr/bin/php artisan storage:link

# Run services
exec "$@"

Dockerfile file:


....


# Set permissions
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

...

Here’s why

Key takeaway: Do file permission setup and symlink creation in entrypoint.sh to ensure it works in the final container runtime environment.