Docker configuration for Magento 2 - full stack cloud infrastructure

 

  •  Install Docker:

you can use any linux host or Docker Desktop
https://docs.docker.com/
https://docs.docker.com/engine/install/debian/

    curl -fsSL https://get.docker.com -o get-docker.sh
    curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    bash get-docker.sh
    chmod +x /usr/local/bin/docker-compose
  •  Create deployment directory:
  mkdir magento && cd magento
  •  Clone repo:
  git clone https://github.com/magenx/Magento-2-docker-configuration.git .

[ ! ] Check all data, adjust your settings, edit your variables

  •  Run to pull and build images and start containers:

to enable buildkit:
echo '{ "features": { "buildkit": true } }' > /etc/docker/daemon.json
export DOCKER_BUILDKIT=1

   docker-compose build --no-cache php
   
   docker-compose build \
        --build-arg magento \
        --build-arg nginx
        
   docker-compose up -d
  •  Watch syslog for errors and issues:
   tail -f /var/log/syslog

 

  •  Run composer or magento command from host:
   docker-compose run --rm composer update
   docker-compose run --rm magento module:status --enabled

 

  •  Source variables and issue magento installation command:
    docker-compose run --rm magento setup:install --base-url=${DOMAIN} \
   --db-host=mariadb \
   --db-name=${MARIADB_NAME} \
   --db-user=${MARIADB_USER} \
   --db-password='${MARIADB_PASSWORD}' \
   --admin-firstname=${ADMIN_FIRSTNAME} \
   --admin-lastname=${ADMIN_LASTNAME} \
   --admin-email=${ADMIN_EMAIL} \
   --admin-user=${ADMIN_LOGIN} \
   --admin-password='${ADMIN_PASSWORD}' \
   --language=${LOCALE} \
   --currency=${CURRENCY} \
   --timezone=${TIMEZONE} \
   --cleanup-database \
   --cache-backend=redis \
   --cache-backend-redis-server=redis-cache \
   --cache-backend-redis-port=6380 \
   --cache-backend-redis-db=0 \
   --cache-backend-redis-compress-data=1 \
   --cache-backend-redis-compression-lib=gzip \
   --cache-backend-redis-password='${REDIS_PASSWORD}' \
   --session-save=redis \
   --session-save-redis-host=redis-session \
   --session-save-redis-port=6379 \
   --session-save-redis-log-level=3 \
   --session-save-redis-db=0 \
   --session-save-redis-compression-lib=gzip \
   --session-save-redis-password='${REDIS_PASSWORD}' \
   --use-rewrites=1 \
   --amqp-host=rabbitmq \
   --amqp-port=5672 \
   --amqp-user=magento \
   --amqp-password='${RABBITMQ_PASSWORD}' \
   --amqp-virtualhost='/' \
   --consumers-wait-for-messages=0 \
   --search-engine=elasticsearch7 \
   --elasticsearch-host=elasticsearch \
   --elasticsearch-port=9200 \
   --elasticsearch-enable-auth=1 \
   --elasticsearch-username=elastic \
   --elasticsearch-password='${ELASTIC_PASSWORD}'

 

  •  Stop all services:
   docker-compose down
   
   Stopping magenx-cron          ... done
   Stopping magenx-nginx         ... done
   Stopping magenx-php           ... done
   Stopping magenx-magento       ... done
   Stopping magenx-elasticsearch ... done
   Stopping magenx-rabbitmq      ... done
   Stopping magenx-varnish       ... done
   Stopping magenx-certbot       ... done
   Stopping magenx-nodejs        ... done
   Stopping magenx-phpmyadmin    ... done
   Stopping magenx-mariadb       ... done
   Stopping magenx-redis         ... done