PHP is unable to see env var when runing in docker

  docker, docker-compose, environment-variables

I have this docker-compose config.

The "app" is a PHP application. As you can see, 3 env vars are passed to the container.
However, after docker-compose up, PHP doesn’t see these. They are not returned by getenv() and they cannot be found $_ENV either.

What’s wrong here?

version: '3.4'
services: 
        db:
            image: postgres:11.0
            restart: always
            environment:
                POSTGRES_PASSWORD: testuser
                POSTGRES_USER: test
                POSTGRES_DB: db
            volumes: 
                - /data/db
        redis:
            image: redis:latest
            restart: always
            volumes: 
                - /data/redis
        app: 
            build:
                context: .
                dockerfile: Dockerfile
            environment: 
                - DATABASE_URL=postgresql://db:5432/db
                - REDIS_URL=tcp://redis:6379?database=1
                - NODE_ENV=development
            ports: 
                - '80:80'
            volumes: 
                - '${BASEDIR}:/var/www/some' 

Source: Docker Questions

LEAVE A COMMENT