Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GodziLaravel's avatar

Docker: Failed to open stream: Permission denied

Hello ,

I try to configure a docker laravel app , when I try to run: docker-compose exec app php artisan key:generate

it returns me permission error :

   UnexpectedValueException
  The stream or file "/var/www/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied

  at vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:146
    142▕             restore_error_handler();
    143▕             if (!is_resource($stream)) {
    144▕                 $this->stream = null;
    145▕
  ➜ 146▕                 throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened in append mode: '.$this->errorMessage, $url));
    147▕             }
    148▕             stream_set_chunk_size($stream, $this->streamChunkSize);
    149▕             $this->stream = $stream;
    150▕         }

      +9 vendor frames
  10  [internal]:0
      Illuminate\Foundation\Bootstrap\HandleExceptions::handleException(Object(UnexpectedValueException))

I'm wondering if this error is related to Dockerfile

Docker file :

FROM php:8.0.0rc1-fpm

# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/

# Set working directory
WORKDIR /var/www

# Install dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    libzip-dev \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install extensions

RUN docker-php-ext-install pdo_mysql zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www

# Copy existing application directory contents
COPY . /var/www

# Copy existing application directory permissions
COPY --chown=www:www . /var/www

# Change current user to www
USER www

# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]

Do I miss something in my Dockerfile ?

0 likes
1 reply

Please or to participate in this conversation.