Docker - PHP environment variables

Hey all, so I’ve been messing with Docker containers for a while and I’ve been trying to spin up my own custom PHP image to use and I’ve come across using environment variables within the containers.

I think I got a working solution, but I don’t think it’s the right approach. I know people have been referencing the DotEnv Composer project for this type of work, but that’s kind of not what I’m looking for. I don’t want to have to predefine a PHP file that then gets a custom .env file.

So my question is, has anyone been successful in passing environment variables into their containers and then using the $_ENV variables to get their environment variables?

The “working” solution I have is pretty much executing the env Linux command, sending the outputs to a .env file, kicking off a PHP file to then parse and loop through that file and then append those values to the www.conf file. After the variables are imported, the .env file gets emptied. On reboot, the same process happens. Seems to be working, but was wondering if anyone has a workaround that might be better.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.