docker.recipes

Magento 2 Full Stack

advanced

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

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.

Key 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

Common Use Cases

  • 1Enterprise e-commerce stores with 10,000+ SKUs requiring advanced search and filtering
  • 2B2B marketplaces needing complex pricing rules, customer groups, and bulk ordering
  • 3Multi-brand retailers managing multiple storefronts from single backend
  • 4Fashion and electronics retailers requiring configurable products with variants
  • 5Development agencies building custom e-commerce solutions for clients
  • 6Businesses migrating from Magento 1.x to modern containerized Magento 2 infrastructure
  • 7High-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

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 mysql:
3 image: mysql:8.0
4 container_name: magento-mysql
5 restart: unless-stopped
6 environment:
7 MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
8 MYSQL_DATABASE: ${MYSQL_DATABASE:-magento}
9 MYSQL_USER: ${MYSQL_USER:-magento}
10 MYSQL_PASSWORD: ${MYSQL_PASSWORD:-magento}
11 volumes:
12 - mysql_data:/var/lib/mysql
13 networks:
14 - magento-network
15
16 redis:
17 image: redis:alpine
18 container_name: magento-redis
19 restart: unless-stopped
20 volumes:
21 - redis_data:/data
22 networks:
23 - magento-network
24
25 elasticsearch:
26 image: elasticsearch:7.17.10
27 container_name: magento-elasticsearch
28 restart: unless-stopped
29 environment:
30 - discovery.type=single-node
31 - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
32 volumes:
33 - es_data:/usr/share/elasticsearch/data
34 networks:
35 - magento-network
36
37 magento:
38 image: bitnami/magento:latest
39 container_name: magento
40 restart: unless-stopped
41 ports:
42 - "${MAGENTO_PORT:-8080}:8080"
43 environment:
44 - MAGENTO_HOST=localhost
45 - MAGENTO_DATABASE_HOST=mysql
46 - MAGENTO_DATABASE_NAME=${MYSQL_DATABASE:-magento}
47 - MAGENTO_DATABASE_USER=${MYSQL_USER:-magento}
48 - MAGENTO_DATABASE_PASSWORD=${MYSQL_PASSWORD:-magento}
49 - ELASTICSEARCH_HOST=elasticsearch
50 - MAGENTO_ELASTICSEARCH_HOST=elasticsearch
51 - MAGENTO_SEARCH_ENGINE=elasticsearch7
52 volumes:
53 - magento_data:/bitnami/magento
54 depends_on:
55 - mysql
56 - redis
57 - elasticsearch
58 networks:
59 - magento-network
60
61volumes:
62 mysql_data:
63 redis_data:
64 es_data:
65 magento_data:
66
67networks:
68 magento-network:
69 driver: bridge

.env Template

.env
1# Magento 2
2MAGENTO_PORT=8080
3MYSQL_ROOT_PASSWORD=root
4MYSQL_DATABASE=magento
5MYSQL_USER=magento
6MYSQL_PASSWORD=magento

Usage Notes

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

Individual Services(4 services)

Copy individual services to mix and match with your existing compose files.

mysql
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
redis:
  image: redis:alpine
  container_name: magento-redis
  restart: unless-stopped
  volumes:
    - redis_data:/data
  networks:
    - magento-network
elasticsearch
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
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

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 mysql:
5 image: mysql:8.0
6 container_name: magento-mysql
7 restart: unless-stopped
8 environment:
9 MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
10 MYSQL_DATABASE: ${MYSQL_DATABASE:-magento}
11 MYSQL_USER: ${MYSQL_USER:-magento}
12 MYSQL_PASSWORD: ${MYSQL_PASSWORD:-magento}
13 volumes:
14 - mysql_data:/var/lib/mysql
15 networks:
16 - magento-network
17
18 redis:
19 image: redis:alpine
20 container_name: magento-redis
21 restart: unless-stopped
22 volumes:
23 - redis_data:/data
24 networks:
25 - magento-network
26
27 elasticsearch:
28 image: elasticsearch:7.17.10
29 container_name: magento-elasticsearch
30 restart: unless-stopped
31 environment:
32 - discovery.type=single-node
33 - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
34 volumes:
35 - es_data:/usr/share/elasticsearch/data
36 networks:
37 - magento-network
38
39 magento:
40 image: bitnami/magento:latest
41 container_name: magento
42 restart: unless-stopped
43 ports:
44 - "${MAGENTO_PORT:-8080}:8080"
45 environment:
46 - MAGENTO_HOST=localhost
47 - MAGENTO_DATABASE_HOST=mysql
48 - MAGENTO_DATABASE_NAME=${MYSQL_DATABASE:-magento}
49 - MAGENTO_DATABASE_USER=${MYSQL_USER:-magento}
50 - MAGENTO_DATABASE_PASSWORD=${MYSQL_PASSWORD:-magento}
51 - ELASTICSEARCH_HOST=elasticsearch
52 - MAGENTO_ELASTICSEARCH_HOST=elasticsearch
53 - MAGENTO_SEARCH_ENGINE=elasticsearch7
54 volumes:
55 - magento_data:/bitnami/magento
56 depends_on:
57 - mysql
58 - redis
59 - elasticsearch
60 networks:
61 - magento-network
62
63volumes:
64 mysql_data:
65 redis_data:
66 es_data:
67 magento_data:
68
69networks:
70 magento-network:
71 driver: bridge
72EOF
73
74# 2. Create the .env file
75cat > .env << 'EOF'
76# Magento 2
77MAGENTO_PORT=8080
78MYSQL_ROOT_PASSWORD=root
79MYSQL_DATABASE=magento
80MYSQL_USER=magento
81MYSQL_PASSWORD=magento
82EOF
83
84# 3. Start the services
85docker compose up -d
86
87# 4. View logs
88docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/magento-full-stack/run | bash

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

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space