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.

  • disable firewalld/iptables in centos7 minimal version
  • How to run docker containers in their network with an external gateway?
  • My Docker container will run a command from within the container, but not with ENTRYPOINT
  • Where should I install SQL Management Server instances on my development machine?
  • How do you set up selenium grid using docker on windows?
  • Issue with docker compose
  • 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]) ?

  • How to get client IP from request inside haproxy docker container?
  • Docker commands via php shell_exec
  • Docker for Windows Host Network Stack Use
  • How to access web app live inside docker in docker
  • How to map docker images to a dockerfile?
  • How to restart a docker service using Shell Script
  • 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.