title: How to set laravel file permissions inside a docker image
body: <p>I have the following dockerfile to build my Laravel web application. After I run it I get permission errors when trying to acccess the <strong>vendor</strong> and <strong>storage</strong> directories. My question is what is the correct way of setting permissions for Laravel for a php:7.2-fpm base image. The error I receive is:</p>
  <blockquote>
  <p>fopen(/var/www/app/vendor/dompdf/dompdf/lib/fonts/glyphicons-halflings-normal_4ced20531a4f462a8c5c535d4debd2eb.ufm):
  failed to open stream: Permission denied</p>
  </blockquote>
  <p>Dockerfile</p>
  <pre><code>FROM php:7.2-fpm
  
  WORKDIR /var/www/app
  
  RUN apt-get update &amp;&amp; apt-get install -y \
      build-essential \
      libpng-dev \
      libjpeg62-turbo-dev \
      libfreetype6-dev \
      locales \
      zip \
      jpegoptim optipng pngquant gifsicle \
      vim \
      unzip \
      git \
      curl \
      npm
  
  RUN curl -sL https://deb.nodesource.com/setup_9.x | bash
  RUN apt-get install -y nodejs 
  
  # Clear cache
  RUN apt-get clean &amp;&amp; rm -rf /var/lib/apt/lists/*
  
  # Install extensions
  RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
  RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
  RUN docker-php-ext-install gd
  RUN docker-php-ext-install bcmath
  
  # Install composer
  RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  
  # Copy existing application directory contents
  
  COPY . /var/www/app
  
  RUN chmod -R 775 /var/www/app
  RUN chmod -R 775 /var/www/app/vendor
  RUN chmod -R 777 /var/www/app/storage
  
  # COPY --from=nodeBuild ./ /var/www
  RUN composer install
  RUN npm install
  RUN npm update
  
  # Expose port 9000 and start php-fpm server
  EXPOSE 9000
  CMD [&quot;php-fpm&quot;]
  </code></pre>