title: AWS Elastic Beanstalk Change Permissions on Mounted Directory
body: <p>I'm deploying a Laravel application to a multicontainer Elastic Beanstalk configuration. The application code is packaged in a zip file and uploaded as part of the deployment, and is then mounted into the PHP-FPM Docker container. The containers run correctly and the code is mounted, however all the mounted directories are owned by <code>root</code> and therefore the application cannot write to these directories (required for log files, framework files etc). I need them to be owned by <code>www-data</code> </p>
  
  <p>If I manually SSH on the the EC2 instance, then run <code>docker exec -it container_id bash</code> and run <code>ls -la</code> I can see all the files/dirs are owned by root. If I run <code>chown -R www-data: storage vendor</code> then the application works as expected. </p>
  
  <p><strong>Therefore I need to find a way to change the permissions on the mounted directories <em>inside</em> the php-fpm container.</strong> </p>
  
  <p>I have tried the following command in <code>.ebextensions/permissions.config</code></p>
  
  <pre><code>container_commands:
    01_change_storage_permissions:
      # Get the php fpm container ID and change permissions on the mounted directories
      command: sudo docker exec $(sudo docker ps -aqf "name=php-fpm") chown -R www-data:www-data storage vendor bootstrap
  </code></pre>
  
  <p>The deployment is successful so I can assume the command executed successfully but it unfortunately doesn't seem to change the permissions as upon logging into the container, the directories are still owned by root</p>