DEV Community

Discussion on: docker-compose up your entire Laravel + Apache + MySQL development environment.

Collapse
 
taviroquai profile image
Marco Afonso

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!

Collapse
 
veevidify profile image
V • Edited

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.