Lumen does not read env from system during request

Lumen 5.4, MySql & Docker. I have following variables in global env

$ printenv
DB_HOST=127.0.0.1
DB_DATABASE=database
etc

.env in my project the are present also, but they have different values.

  • How do I provide dynamic host names for all docker containers?
  • Docker Selenium-Chrome container memory utilization
  • Docker - Ubuntu + Apache symbolic links permissions error
  • Run command as --privileged in Dockerfile
  • Can I create wheels for python packages on macOS usable for a ubuntu docker image?
  • Dockerized multi-node Cassandra cluster with CDH
  • If I type in tinker env('DB_HOST'), it prints value from the global environment, but when application runs, it takes from the specified .env file. I think the problem exists within following function in Laravel\Lumen\Application :

    /**
     * Load a configuration file into the application.
     *
     * @param  string  $name
     * @return void
     */
    public function configure($name)
    {
        if (isset($this->loadedConfigurations[$name])) {
            return;
        }
    
        $this->loadedConfigurations[$name] = true;
    
        $path = $this->getConfigurationPath($name);
    
        if ($path) {
            $this->make('config')->set($name, require $path);
        }
    }
    

    How to override those values or make it to avoid those conditions: isset($this->loadedConfigurations[$name]) ?

  • Docker on Cent OS 6 fails to build container after switching to different container directory
  • How to speed up an Azure web application deployment with lots of files?
  • Why my array suddenly lose all its content
  • Docker - Ubuntu + Apache symbolic links permissions error
  • separate applications on kubernetes cluster
  • Reading and writing files with dockerimage
  • One Solution collect form web for “Lumen does not read env from system during request”

    I still think that, regarding my comment, the answer remains the same. If you wish to utilize the docker environment variables as opposed to your local .env variables, then the config directory is still the way to go. In this case, it looks like you wish to target the database host. So let’s do that:

    In your config/database.php file, change the following:

    'mysql' => [
        //...
        'host' => getenv('DB_HOST') ?: env('DB_HOST', 'defaultvalue')
    ] 
    

    Then only make reference to the host through the config file.

    config("database.mysql.host");
    

    You will get the ENV from your docker container if it exists, otherwise you will get the DB_HOST declaration from your .env file.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.