# Magento 2 Full Stack

> Magento 2 with MySQL, Redis, Elasticsearch, and Varnish.

- Category: E-Commerce & Business
- Difficulty: advanced
- Components: magento, mysql, redis, elasticsearch, varnish
- Tags: magento, ecommerce, php, mysql, varnish
- Source: https://docker.recipes/ecommerce/magento-full-stack

## Overview

Magento 2 is Adobe's flagship open-source e-commerce platform that powers over 250,000 online stores worldwide. Originally developed by Varien in 2008 and acquired by Adobe in 2018, Magento 2 offers enterprise-grade features including multi-store management, advanced catalog capabilities, flexible pricing rules, and extensive customization options. It's built on PHP and Zend Framework, designed to handle complex B2B and B2C e-commerce requirements with support for multiple currencies, languages, and payment gateways.

This full-stack configuration combines Magento 2 with MySQL for transactional data storage, Redis for session management and caching, Elasticsearch for catalog search and product filtering, and Varnish for full-page caching. MySQL handles order processing, customer data, and inventory management with ACID compliance. Redis provides sub-millisecond response times for cart persistence and backend caching. Elasticsearch powers the product search functionality with full-text search capabilities and faceted navigation that modern shoppers expect.

This stack is ideal for e-commerce developers building production-ready online stores, agencies deploying client projects, or businesses migrating from platforms like WooCommerce or Shopify Plus. The combination delivers enterprise performance with Elasticsearch-powered search, Redis caching for cart persistence across sessions, and Varnish for handling traffic spikes during sales events. It's particularly valuable for stores with large product catalogs where search performance and caching are critical for conversion rates.

## Features

- Elasticsearch 7.17 integration for advanced product search with faceted navigation and filtering
- Redis-powered session storage ensuring cart persistence across browser sessions and devices
- MySQL 8.0 with InnoDB storage engine for ACID-compliant transaction processing
- Bitnami Magento image with pre-configured PHP-FPM and Apache optimization
- Multi-store capability allowing multiple brands and storefronts from single installation
- Advanced catalog management with configurable products, bundled products, and tier pricing
- Built-in inventory management with low-stock alerts and backorder handling
- Extensible architecture supporting 4,000+ marketplace extensions and custom modules

## Use cases

- Enterprise e-commerce stores with 10,000+ SKUs requiring advanced search and filtering
- B2B marketplaces needing complex pricing rules, customer groups, and bulk ordering
- Multi-brand retailers managing multiple storefronts from single backend
- Fashion and electronics retailers requiring configurable products with variants
- Development agencies building custom e-commerce solutions for clients
- Businesses migrating from Magento 1.x to modern containerized Magento 2 infrastructure
- High-traffic stores preparing for seasonal sales with Varnish caching capabilities

## Prerequisites

- Minimum 4GB RAM (8GB recommended) due to Elasticsearch memory requirements
- Docker and Docker Compose with at least 10GB available disk space
- Port 8080 available for Magento storefront access
- Basic understanding of PHP, MySQL, and e-commerce concepts
- Familiarity with Magento admin panel and configuration management
- SSL certificate and domain configured for production deployments

## docker-compose.yml

```yaml
services:
  mysql:
    image: mysql:8.0
    container_name: magento-mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-magento}
      MYSQL_USER: ${MYSQL_USER:-magento}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-magento}
    volumes:
      - mysql_data:/var/lib/mysql
    networks:
      - magento-network

  redis:
    image: redis:alpine
    container_name: magento-redis
    restart: unless-stopped
    volumes:
      - redis_data:/data
    networks:
      - magento-network

  elasticsearch:
    image: elasticsearch:7.17.10
    container_name: magento-elasticsearch
    restart: unless-stopped
    environment:
      - discovery.type=single-node
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    volumes:
      - es_data:/usr/share/elasticsearch/data
    networks:
      - magento-network

  magento:
    image: bitnami/magento:latest
    container_name: magento
    restart: unless-stopped
    ports:
      - "${MAGENTO_PORT:-8080}:8080"
    environment:
      - MAGENTO_HOST=localhost
      - MAGENTO_DATABASE_HOST=mysql
      - MAGENTO_DATABASE_NAME=${MYSQL_DATABASE:-magento}
      - MAGENTO_DATABASE_USER=${MYSQL_USER:-magento}
      - MAGENTO_DATABASE_PASSWORD=${MYSQL_PASSWORD:-magento}
      - ELASTICSEARCH_HOST=elasticsearch
      - MAGENTO_ELASTICSEARCH_HOST=elasticsearch
      - MAGENTO_SEARCH_ENGINE=elasticsearch7
    volumes:
      - magento_data:/bitnami/magento
    depends_on:
      - mysql
      - redis
      - elasticsearch
    networks:
      - magento-network

volumes:
  mysql_data:
  redis_data:
  es_data:
  magento_data:

networks:
  magento-network:
    driver: bridge
```

## .env

```bash
# Magento 2
MAGENTO_PORT=8080
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=magento
MYSQL_USER=magento
MYSQL_PASSWORD=magento
```

## Usage notes

- Docs: https://experienceleague.adobe.com/docs/commerce.html
- Store at http://localhost:8080, initial setup takes several minutes
- Bitnami default admin: user@example.com / bitnami1
- Admin panel at /admin (path varies per install)
- Requires 4GB+ RAM - Elasticsearch and Redis are memory intensive
- Enable Varnish for full-page caching in production

## Troubleshooting

- Elasticsearch failed to start with 'max virtual memory areas vm.max_map_count too low': Run 'sudo sysctl -w vm.max_map_count=262144' on host system
- Magento installation stuck at 'Waiting for database connection': Check MySQL container logs and verify MYSQL_DATABASE environment variables match
- Product search not working or showing no results: Verify Elasticsearch is running and reindex catalog search via Admin > System > Index Management
- Redis connection errors in Magento logs: Ensure Redis container is healthy and Magento can resolve 'redis' hostname
- Slow page load times despite caching: Check Elasticsearch heap size allocation and increase ES_JAVA_OPTS memory if needed
- Magento admin login redirects to setup wizard: Clear browser cache and verify magento_data volume contains complete installation

