markshust/docker-magento
Table of contents
- Docker Hub
- Free Course
- Usage
- Prerequisites
- Setup
- Updates
- Custom CLI Commands
- Misc Info
- Known Issues
- Credits
- License
Docker Hub
View Dockerfiles for the latest tags:
- markoshust/magento-nginx (Docker Hub)
- markoshust/magento-php (Docker Hub)
- markoshust/magento-opensearch (Docker Hub)
- markoshust/magento-elasticsearch (Docker Hub)
- markoshust/magento-rabbitmq (Docker Hub)
- markoshust/ssh (Docker Hub)
Free Course
This course is sponsored by M.academy, the simplest way to learn Magento.
A free screencast course is available (which was fully refreshed in December 2021), which details the basic usage of this project:
Set Up a Magento 2 Development Environment with Docker
Course Curriculum
Intro
Initial Project Setup
- Install Docker Desktop & configure preferences
- Set up Magento with the automated onelinesetup script
- Set up Magento manually from a custom Git branch
- Set up Docker for an existing Magento project
The Basics of docker-magento
- Execute docker-magento helper scripts
- Start, stop, restart and check container status
- Execute bin/magento and composer within Docker containers
- Install Magento sample data
Docker Filesystem & Data Volumes
PhpStorm
Code Quality Tools
- Configure PHPCS (PHP CodeSniffer) for Magento
- Configure PHPCSF (PHP CodeSniffer Fixer) for Magento
- Configure PHPMD (PHP Mess Detector) for Magento
Xdebug
- Install the Xdebug helper browser plugin for Chrome & PhpStorm
- Enable disable check the status of Xdebug
- Configure PhpStorm for Xdebug connections
- Trigger an Xdebug breakpoint in PhpStorm
- Trigger an Xdebug breakpoint for CLI commands in PhpStorm
Customize Server Configurations
- Understand the docker-compose application structure
- Increase the PHP memory limit in php.ini
- Increase the Nginx request timeout in nginx.conf
- Increase the MySQL buffer pool size with command or in my.cnf
- Install a new PHP extension by building a custom Docker image
- Configure multi-store instances in Docker with Nginx
Usage
This configuration is intended to be used as a Docker-based development environment for Magento 2.
Folders:
images
: Docker images for nginx and phpcompose
: sample setups with Docker Compose
The Magento 1 version of this development environment has been deprecated and is no longer supported. PHP 5 was used as it's base, and that version has reached end-of-life. If you still wish to use this setup, please reference compose/magento-1 on tag 20.1.1, but please be aware these images are no longer maintained.
Prerequisites
This setup assumes you are running Docker on a computer with at least 6GB of RAM allocated to Docker, a dual-core, and an SSD hard drive. Download & Install Docker Desktop.
This configuration has been tested on Mac & Linux. Windows is supported through the use of Docker on WSL.
Setup
Automated Setup (New Project)
# Create your project directory then go into it:
mkdir -p ~/Sites/magento
cd $_
# Run this automated one-liner from the directory you want to install your project.
curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/onelinesetup | bash -s -- magento.test 2.4.7 community
The magento.test
above defines the hostname to use, and the 2.4.7
defines the Magento version to install. Note that since we need a write to /etc/hosts
for DNS resolution, you will be prompted for your system password during setup.
After the one-liner above completes running, you should be able to access your site at https://magento.test
.
Install sample data
After the above installation is complete, run the following lines to install sample data:
bin/magento sampledata:deploy
bin/magento setup:upgrade
Manual Setup
Same result as the one-liner above. Just replace magento.test
references with the hostname that you wish to use.
New Projects
# Create your project directory then go into it:
mkdir -p ~/Sites/magento
cd $_
# Download the Docker Compose template:
curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash
# Download the version of Magento you want to use with:
bin/download 2.4.7 community
# You can specify the version and type (community, enterprise, mageos, mageos-nightly, mageos-mirror, mageos-hypernode-mirror, or mageos-maxcluster-mirror).
# The mageos type is an alias for mageos-mirror.
# If no arguments are passed, "2.4.7" and "community" are the default values used.
# or for Magento core development:
# bin/start --no-dev
# bin/setup-composer-auth
# bin/cli git clone git@github.com:magento/magento2.git .
# bin/cli git checkout 2.4-develop
# bin/composer install
# Want to install Magento <2.4.6? In bin/setup-install, replace the lines:
# --elasticsearch-host="$ES_HOST" \
# --elasticsearch-port="$ES_PORT" \
# --opensearch-host="$OPENSEARCH_HOST" \
# --opensearch-port="$OPENSEARCH_PORT" \
# --search-engine=opensearch \
# with:
# --elasticsearch-host="$ES_HOST" \
# --elasticsearch-port="$ES_PORT" \
# --search-engine=elasticsearch7 \
# Run the setup installer for Magento:
bin/setup magento.test
open https://magento.test
Existing Projects
# Create your project directory then go into it:
mkdir -p ~/Sites/magento
cd $_
# Download the Docker Compose template:
curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash
# Take a backup of your existing database:
bin/mysqldump > ~/Sites/existing/magento.sql
# Replace with existing source code of your existing Magento instance:
cp -R ~/Sites/existing src
# or: git clone git@github.com:myrepo.git src
# Start some containers, copy files to them and then restart the containers:
bin/start --no-dev
bin/copytocontainer --all ## Initial copy will take a few minutes...
# If your vendor directory was empty, populate it with:
bin/composer install
# Import existing database:
bin/mysql < ../existing/magento.sql
# Update database connection details to use the above Docker MySQL credentials:
# Also note: creds for the MySQL server are defined at startup from env/db.env
# vi src/app/etc/env.php
# Import app-specific environment settings:
bin/magento app:config:import
# Create a DNS host entry and setup Magento base url
bin/setup-domain yoursite.test
bin/restart
open https://magento.test
Elasticsearch vs OpenSearch
OpenSearch is set as the default search engine when setting up this project. Follow the instructions below if you want to use Elasticsearch instead:
- Comment out or remove the
opensearch
container in both thecompose.yaml
andcompose.healthcheck.yaml
files - Uncomment the
elasticsearch
container in both thecompose.yaml
andcompose.healthcheck.yaml
files - Update the
bin/setup-install
command to use the Elasticsearch ratther than OpenSearch. Change:
--opensearch-host="$OPENSEARCH_HOST" \
--opensearch-port="$OPENSEARCH_PORT"