Home

Awesome

Magento 2.4 environment under Docker

Technologies Used

Feature highlights

Contents Overview

  1. Pre-Requistices
  2. Follow these steps to setup the enviroment
  3. Install Magento 2
  4. Finalize setup
  5. Extra optimizations

1. Pre-Requistices

2. Follow these steps to setup the enviroment

- Create folders in host that will be mounted to docker containers
- Configure proper permissions
- Optimize host for elasticsearch / redis
- Configure docker-compose environment file
- Configure host environment for frequent commands
subjectlocal initializeserver initialize
override compose filedocker-compose.local.ymldocker-compose.server.yml
mage_root/home/$HOST_USER/html/magento/var/www/html/$DOMAIN_NAME
auto restart policyneverunless-stopped
nginx sever_name / ssllocalhost / no ssl$DOMAIN_NAME / with ssl
php fpm pool max childstatic, 6static, 14
varnish memory256 mb512 mb
elasticsearch memory256 mb512 mb
cron / rabbitmqoptional, add manually if neededinstalled

Local initialize

sudo ./local-initialize.sh

Server initialize

sudo ./server-initialize.sh $domain_name

Enviroment variables for frequent commands

Commands for other services

Up the docker enviromnment

$magento_stack up -d
$magento_stack ps

Generate ssl certificates and setup renew hook for installation on server

sudo rm -r /etc/letsencrypt/live/*
 sudo certbot certonly --webroot -w /var/www/html/$domain_name -d $domain_name
deploy-hook = docker exec -it nginx nginx -s reload

3. Install Magento 2

Existing project

Clone your project and install packages

git clone $project_repository_link .

$cli_composer install

Configure existing enviroment

Install existing data and media

New project

Create new composer project and install packages

$cli_composer create-project --repository=https://repo.magento.com/ magento/project-community-edition .
$cli_composer create-project --repository=https://repo.magento.com/ magento/project-enterprise-edition .

Configure new enviroment

Install sample data

$cli_magento sampledata:deploy

4. Finalize setup

$cli_magento setup:upgrade
$cli_magento indexer:reindex
$cli_magento cache:flush

5. Extra optimizations

Elasticsearch replicas configuration

# Replica setting for all new index

curl -XPUT "localhost:9200/_template/default_template" -H 'Content-Type: application/json' -d'
{
  "index_patterns": ["*"],
  "settings": {
    "index": {
      "number_of_replicas": 0
    }
  }
}'

# Replica setting for current index

curl -XPUT 'localhost:9200/_settings' -H 'Content-Type: application/json' -d'
{
  "index" : {
    "number_of_replicas" : 0
  }
}'