title: docker and php: getting dependencies (composer) into the container
body: <p>A little context: I am new to docker and dont know of any best-practices yet. My task is to create a webservice based on php and i decided to use docker-compose for provisioning.</p>
  
  <p>Because we are all fancy devs, we know - there is no way to build a php application without using composer these days.</p>
  
  <h1>My question:</h1>
  
  <p>Should i install dependencies in the build? So by adding this to my Dockerfile:</p>
  
  <pre><code>RUN cd /app &amp;&amp; composer install --no-interaction --prefer-source --optimize-autoloader
  </code></pre>
  
  <p>Or should i install dependencies during development and build the container image with included dependencies?</p>
  
  <hr>
  
  <p>I only know of one way NOT to do it: install dependencies locally on the dev machine and build the container afterwards. But how would the "best practice" look like?</p>
  
  <p>And - because i am a newbee in this field - how would i run a "composer require some/package" for my app service container?</p>
  
  <h1>By the way</h1>
  
  <p>I also noticed a message "Do not run Composer as root/super user!" when building the container. I added <code>COMPOSER_ALLOW_SUPERUSER=1</code> to my Env file (as seen <a href="https://getcomposer.org/doc/03-cli.md#composer-allow-superuser" rel="noreferrer">here</a>), but this message still appears.</p>
  
  <p>Is it possible to NOT execute composer install as root in a docker container? Can i ignore that message?</p>
  
  <p>Thanks in advance,
  Philipp</p>