title: How to prepare env file for symfony app in docker?
body: <p>I am trying to run a <code>symfony</code> application i dockerized environment. To do so, I'd like <code>docker-compose</code> to fetch all the variables like db credentials or <code>APP_SECRET</code> from docker <code>.env</code> file and apply those values to some predefined <code>.env.dist</code>. So I have something like that in my <code>Dockerfile</code> for PHP container:</p>
  
  <pre><code>COPY ./app/.env.dist /var/www/app/.env
  RUN sed -i 's/__APP_ENV__/'${APP_ENV}'/g' /var/www/app/.env
  RUN sed -i 's/__APP_SECRET__/'${APP_SECRET}'/g' /var/www/app/.env
  ...
  </code></pre>
  
  <p>However, the problem is that these instructions are obviously executed before the volume is mounted so after the container is built and up the <code>.env</code> file I prepare with those commands is missing because the directory gets replaced with the mounted one. Is there a way to handle such situation in a nice way?</p>
  
  <p>Basically, anything that could prepare an env file before build would be ok for me.</p>