This article explains how to build a Docker image from scratch or existing projects in three simple steps. It starts with an overview for readers whose daily work might not be related to build pipelines and deployment processes. For admins and seniors, who already opened their shell, jump to the “DevOps time” chapter to get the practical takeaway of the article.
Docker has two critical phases: An image build phase and the startup of the container. Usually they are timely and physically separated. The build process runs on a build server (Gitlab, Jenkins). Generated images are pushed to a Docker registry (e.g. Gitlab, Google Container Registry or Docker Hub). On deployment they get pulled from the registry on the target machine.
Back in the days of Magento1 a build phase basically didn’t exist. Magento1 did everything for the developers (like merging CSS and JS files) on the fly. When Less/Sass became more popular some developers started to use Grunt to compile their CSS and minify JavaScript files. The cool kids even used Composer and Modman to install dependencies and libraries. Some of these steps could be already considered as “build phase”. They installed dependencies and prepared the code in the Git repository for optimal execution in a production environment.
When switching from developer to _production _mode (bin/magento deploy:mode:set production) at least setup:di:compile and setup:static-content:deploy get executed. The Magento DevDocs has a diagram which explains the detailed steps. It also mentions the configuration as an important ingredient for Magento’s build phase. In our approach the last step of the process „Check the compiled and static view files into repository” is the phase where the built Docker image is saved in the Docker registry.
Since Magento 2.1 a database connection isn’t necessary anymore to run SCD (static content deployment). This is possible by adding information about stores, settings and modules to the “shared configuration”, located at a_pp/etc/config.php._ In the build phase also Composer dependencies get resolved based on the c_omposer.lock _file.
#magento-2 #docker #kubernetes #devops