0
votes

This is what I have in my .yml:

version: '2'

services:
  ## Wordpress Container
  wordpress:
    ...

  ## MySql
  mysql:
    ...

  ## Nginx Container
  nginx:
    container_name: afp_nginx
    image: ng:afp
    environment:
      PHP_FPM_SOCK: wordpress:9000
      SERVER_NAME: wordpress.dev
      ENV: stage
    ports:
      - 8080:80
    volumes:
      - ./x_wordpress:/var/www/html
      - ./x_nginx/ssl:/etc/nginx/ssl

  ## Composer Container
  composer:
    ...

When I console.log(process.env.ENV) I get undefined.
When I var_dump($_ENV) my variable ENV is not defined either.
However, when I run $ docker exec afp_nginx printenv ENV I get the correct output 'stage'.

How do I access the value of ENV inside my application (in a javascript file, or in PHP)?
Should it be declared in composer instead of nginx, or somewhere else?

Thanks

2

2 Answers

1
votes

Another way of doing it, besides of Dockerfile syntax, is using -e flag running your docker image, for example:

docker run -eENV_VARIABLE_NAME=value hello-world
0
votes

Found it!
It needs to be declared in the wordpress container like so:

services:
  ## Wordpress Container
  wordpress:
    ...
    environment:
      ...
      ENV: development

Then it can be accessed inside in $_ENV.

I still need a simple way to access it in javascript, since it still isn't showing in process.env.ENV