title: docker-compose.yml environment variable to php environment variable
body: <p>Trying to do the following: Propagate environment values from .env file to php file environment values.</p>
  <p>Set MYSQL variables in .env file.</p>
  <pre><code>#cat .env
  MYSQL_ROOT_PASSWORD=RootPassword
  MYSQL_USER=gnf_user
  MYSQL_PASSWORD=UserPassword
  MYSQL_DATABASE=gnf_noah
  MYSQL_HOST=db
  </code></pre>
  <p>I would like that to propagate to my container. So I do:</p>
  <pre><code>#cat docker-compose.yml
  version: &quot;3.2&quot;
  services:
   www:
    build: . #Include Dockerfile in current directory
    ports:
    - &quot;30001:80&quot;
    - &quot;30443:443&quot;
    expose:
    - &quot;80&quot;
    - &quot;443&quot;
    volumes:
    - &quot;var:/var/www/html/var/&quot;
    environment:
     MYSQL_HOST: ${MYSQL_HOST}
     MYSQL_DATABASE: ${MYSQL_DATABASE}
     MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
     MYSQL_USER: ${MYSQL_USER}
     MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    restart: always
    networks:
    - frontend
    - backend
    links:
    - db:db
  # shortend for readability ;-)
  </code></pre>
  <p>Now, trying in my container to grab those values:</p>
  <pre><code>$db_host = getenv('MYSQL_HOST', true) ?: getenv('MYSQL_HOST');
  $db_name = getenv('MYSQL_DATABASE', true) ?: getenv('MYSQL_DATABASE');
  $db_user = getenv('MYSQL_USER', true) ?: getenv('MYSQL_USER');
  $db_pwd  = getenv('MYSQL_PASSWORD', true) ?: getenv('MYSQL_PASSWORD');
  </code></pre>
  <p>Gives empty values.</p>
  <p>Am I on the totally wrong page here.. or do I need a script to set those values on build time eg. in /docker-entrypoint-init.d&quot; or something like that?</p>
  <p>(EDIT) Files used:</p>
  <pre><code>drwxr-xr-x  2 root root  4096 Aug 16 18:54 conf
  -rw-r--r--  1 root root  1406 Aug 17 17:17 docker-compose.yaml
  -rw-r--r--  1 root root   992 Aug 17 19:31 Dockerfile
  drwxr-xr-x  2 root root  4096 Aug 17 14:45 dump
  -rw-r--r--  1 root root   125 Aug 17 07:06 .env
  -rw-r--r--  1 root root 55799 Aug  6 20:10 install-php-extensions
  drwxr-xr-x  2 root root  4096 Aug 13 08:36 mysql
  drwxrwxr-x 25 root 1005  4096 Aug 18 05:40 www
  </code></pre>