I'm setting up a complete automated deployment of a laravel app using docker and I found that Laravel uses .env files instead of docker-compose.yml enviroment section.
Is there a way to make laravel to use docker-compose.yml environment section?
Right, so what .env essentially does is that it emulates Laravel reading the actual runtime environment variables. In other words Laravel treats .env variables as if they're your actual host or build context's environment variables. Conveniently for us, docker-compose is also able to read from .env.
So to put it clearly, both Laravel and docker read these variables in a build context, which are mocked by .env file for development purposes.
In your deployment / build context, you would want to export these variables too. To name a few, Gitlab CI allows configuring them under Settings > CI/CD. Circle CI does also, under Build Settings > Environment Variables. If you only deploy from local (instead of remote CI), simply run deployment from within a container built with .env variables exported.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for this writting :)
I'm setting up a complete automated deployment of a laravel app using docker and I found that Laravel uses .env files instead of docker-compose.yml enviroment section.
Is there a way to make laravel to use docker-compose.yml environment section?
Thanks!
Right, so what
.env
essentially does is that it emulates Laravel reading the actual runtime environment variables. In other words Laravel treats.env
variables as if they're your actual host or build context's environment variables. Conveniently for us,docker-compose
is also able to read from.env
.So to put it clearly, both Laravel and docker read these variables in a build context, which are mocked by
.env
file for development purposes.In your deployment / build context, you would want to export these variables too. To name a few, Gitlab CI allows configuring them under Settings > CI/CD. Circle CI does also, under Build Settings > Environment Variables. If you only deploy from local (instead of remote CI), simply run deployment from within a container built with
.env
variables exported.