Gerico
Gerico

Reputation: 5169

Docker - Pass a environment setting via docker-compose

I am new to Docker and have a working docker-compose file, apart from one part. What I want to achieve is to set an environment setting so that in my PHP application I can use some variables to determine which resources I load in.

In MAMP PRO, for instance, you can access environment settings on this page:

enter image description here.

In my docker-compose file I have the following:

services:
  webserver:
    build: ./docker/webserver
    image: perch
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - C:/websites/sitename/www:/var/www/html
    links:
      - db
    environment:
      - DEVELOPER_ENV=development

At the moment the variable - from what I can tell - isn't being set as my php variables to detect the environment, fail. Any pointers would be appreciated.

Upvotes: 1

Views: 890

Answers (1)

Mormund
Mormund

Reputation: 368

Apache by default removes most environment variables for security reasons.
But you can whitelist variables in the etc/apache2/conf-enabled/expose-env.conf file.

So I added theses commands to my dockerfile: RUN echo 'PassEnv DB_PW' >> /etc/apache2/conf-enabled/expose-env.conf \ && echo 'PassEnv DB_USER' >> /etc/apache2/conf-enabled/expose-env.conf

Alternatively you can copy or mount the expose-env.conf.

Upvotes: 1

Related Questions