This guide covers performance optimization techniques for your Docker development environment.
Composer can consume significant memory. Increase the limit:
In .env:
COMPOSER_MEMORY_LIMIT=-1This is the default in the environment (unlimited memory).
Use Composer 2 for better performance:
dev composer2 installComposer 2 is significantly faster than Composer 1.
Disable platform requirements check for faster installs:
dev composer2 install --no-plugins --no-scriptsOr configure globally:
dev composer2 config platform-check falseComposer 2 automatically downloads packages in parallel. For Composer 1:
dev composer1 global require hirak/prestissimoOPcache is enabled by default in PHP containers. Verify:
dev php -i | grep opcacheIncrease PHP memory limit for resource-intensive scripts:
dev php -d memory_limit=512M script.phpOr set globally in docker-custom.yml:
services:
php82:
environment:
PHP_MEMORY_LIMIT: 512MFor long-running scripts:
dev php -d max_execution_time=300 script.phpOptimize MySQL in conf/mysql/my.cnf:
[mysqld]
# Memory
innodb_buffer_pool_size = 2G
key_buffer_size = 256M
max_allowed_packet = 64M
# Connections
max_connections = 200
# Query cache (MySQL 5.7 only)
query_cache_type = 1
query_cache_size = 64M
# InnoDB
innodb_flush_log_at_trx_commit = 2
innodb_log_file_size = 256M
# Temporary tables
tmp_table_size = 64M
max_heap_table_size = 64MAfter changes:
dev restart dbEnable slow query logging:
[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2View slow queries:
dev exec db tail -f /var/log/mysql/slow.logFind tables without indexes:
SELECT DISTINCT
tables.table_schema,
tables.table_name
FROM information_schema.tables
LEFT JOIN information_schema.statistics
ON tables.table_schema = statistics.table_schema
AND tables.table_name = statistics.table_name
WHERE statistics.index_name IS NULL
AND tables.table_schema NOT IN ('mysql', 'information_schema', 'performance_schema')
AND tables.table_type = 'BASE TABLE';Linux: Native performance, no optimization needed.
macOS/Windows: Use Docker volumes instead of bind mounts:
dev volume workspace workspaceThis significantly improves I/O performance.
Allocate more resources to Docker:
Docker Desktop Settings:
- CPUs: 4+ cores recommended
- Memory: 8+ GB recommended
- Swap: 2+ GB
- Disk image size: 100+ GB
Enable Docker BuildKit for faster builds:
export DOCKER_BUILDKIT=1Add to ~/.bashrc or ~/.zshrc for persistence.
Optimize Dockerfile layer caching by ordering commands from least to most frequently changed:
# Rarely changes - good for caching
FROM php:8.2-fpm
# System packages - changes occasionally
RUN apt-get update && apt-get install -y \
package1 package2
# PHP extensions - changes occasionally
RUN docker-php-ext-install pdo_mysql
# Application dependencies - changes more frequently
COPY composer.json composer.lock ./
RUN composer install --no-dev
# Application code - changes most frequently
COPY . .Set JVM heap size (should be 50% of available RAM, max 32GB):
services:
elasticsearch:
environment:
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"In docker-custom.yml:
services:
elasticsearch:
environment:
- bootstrap.memory_lock=true
ulimits:
memlock:
soft: -1
hard: -1Increase Varnish cache size in .env:
CACHE_SIZE=1GCheck Varnish hit rate:
dev exec varnish varnishadm statsLook for cache_hit vs cache_miss ratio.
For development, disable persistence for better performance:
services:
redis:
command: redis-server --appendonly no --save ""Set max memory:
services:
redis:
command: redis-server --maxmemory 256mb --maxmemory-policy allkeys-lruProduction Mode:
dev console bin/magento deploy:mode:set production
dev console bin/magento cache:flushFlat Catalog: Enable flat tables for categories and products:
- Stores > Configuration > Catalog > Catalog
- Enable "Use Flat Catalog Category"
- Enable "Use Flat Catalog Product"
Indexers: Switch to "Update on Schedule":
dev console bin/magento indexer:set-mode schedule catalog_category_product
dev console bin/magento indexer:set-mode schedule catalog_product_category
# ... etc for all indexersStatic Content: Deploy static content:
dev console bin/magento setup:static-content:deploy -fConfig Caching:
dev console php artisan config:cache
dev console php artisan route:cache
dev console php artisan view:cacheOPcache: Already enabled in PHP containers.
Monitor resource usage:
dev topCheck which container is consuming resources:
docker statsUse Blackfire for application profiling:
dev blackfire curl http://your-site.localhostProblem: File operations (composer, npm) are slow. Solution: Use Docker volumes instead of bind mounts (macOS/Windows).
Problem: Constant high CPU. Solution: Check logs for errors causing retry loops:
dev logsProblem: Containers crashing or OOM errors. Solution:
- Increase Docker Desktop memory allocation
- Reduce container memory limits
- Optimize application memory usage
Problem: Slow database queries. Solution:
- Enable slow query log
- Add indexes
- Optimize queries
- Increase
innodb_buffer_pool_size
dev myroot -e "SHOW ENGINE INNODB STATUS\G"Use Apache Bench:
dev exec php ab -n 1000 -c 10 http://your-site.localhost/Compare script execution time:
time dev php script.php- monitoring-tools.md - Performance monitoring
- advanced-docker-configuration.md - Resource limits
- configure-blackfire.md - Application profiling