env.php in Docker containers with pipeline deployment
-
14-04-2021 - |
Question
I wanna be able to deploy and run Magento 2 using Docker images
I am following Magento 2.2+ pipeline deployment docs:
https://devdocs.magento.com/guides/v2.4/config-guide/deployment/
When runnning pre-build php image with Magento source code, I need to create app/etc/env.php
I have tried to set configuration for env.php via bin/magento setup:config:set
in my entrpoint (from ENV vars) which creates env.php file, but it does not include a way how to set 'install' => ['date' => 'Fri, 31 Jun 2020 18:00:00 +0000']
configuration. So Magento still does not know, that system is installed, and redirects to /setup.
Magento installation runs seprately (before runtime containers are created), and runtime containers should be able to scale easily.
And I dont want to rely on Docker volumes to bind app/etc/ folder to runtime containers. Containers should be self sufficient.
Am I missing something?
Thanks
Solution
I am not generating env.php via bin/magento setup:config:setup
, instead I run setup:install
in different container before I startup my php-fpm containers.
This setup container at the end copies its (newely generated) app/etc/env.php into shared volume (ex. app/init).
Then, when php-fpm container starts, its entrypoint copies this pre-generated env.php from shared volume to its app/etc/env.php.
This way all the containers are immutabble and deterministic.