Skip to content

ityetti/magento2-docker

Repository files navigation

Magento 2

Magento 2 Docker to Development (For Apple Silicon)

Nginx (1.22) + Redis (7.0) + PHP-FPM (8.2) + MySQL (8.0.34) + XDebug (3.2.2) + Mailhog + RabbitMQ (3.11) + OpenSearch (2.5.0) + Varnish (7.3)

The docker stack is composed of the following containers

  • redis
  • rabbitmq
  • opensearch
  • opensearch dashboard
  • mailhog
  • php-fpm
  • nginx
  • mysql
  • nginx-proxy
  • varnish

Container nginx

Builds from the nginx folder.
Mounts the folder magento2 from the project main folder into the container volume /home/magento.

Container nginx-proxy

Starts a nginx-proxy container for use VIRTUAL_HOST.
Opens local port: 80

Container php-fpm

Builds from the php-fpm folder.
Mounts the folder magento2 from the project main folder into the container volume /home/magento.
This container includes all dependencies for magento 2 (Also contain composer, code sniffer, xDebug etc.).

Container redis:

Starts a redis container.
Opens up port: 6379

Container mysql:

Please change or set the mysql environment variables

MYSQL_DATABASE: 'xxxx'
MYSQL_ROOT_PASSWORD: 'xxxx'
MYSQL_USER: 'xxxx'
MYSQL_PASSWORD: 'xxxx'
MYSQL_ALLOW_EMPTY_PASSWORD: 'xxxxx'

Default values:

MYSQL_DATABASE: 'magento_db'
MYSQL_ROOT_PASSWORD: 'root_pass'
MYSQL_USER: 'magento_user'
MYSQL_PASSWORD: 'PASSWD#'
MYSQL_ALLOW_EMPTY_PASSWORD: 'false'

Opens up port: 3306

Note: On your host, port 3306 might already be in use. So before running docker-compose.yml, under the docker-compose.yml's mysql section change the host's port number to something other than 3306, select any as long as that port is not already being used locally on your machine.

Container mailhog:

Starts a mailhog container.
Opens up port: 1025 and 8025

Container rabbitmq:

Starts a rabbitmq container.
Opens up port: 5672 and 15672

Container opensearch:

Starts an opensearch container.
Opens up port: 9200 and 9600

Container opensearch-dashboard:

Starts an opensearch dashboard container.
Opens up port: 5601

Container varnish:

Starts a varnish container.
Opens up port: 6082

Setup

Edit your .env file in root folder, change PROJECT_NAME and PROJECT_VIRTUAL_HOST:
PROJECT_NAME - help you to create simple and clear container names.
PROJECT_VIRTUAL_HOST - it is your main url address.
For example:

PROJECT_NAME=magento2
PROJECT_VIRTUAL_HOST=magento2.test

Edit your /etc/hosts and add next line:
127.0.0.1 magento2.test mail.magento2.test search.magento2.test dashboard.magento2.test rabbit.magento2.test

To start/build the stack.
Use - docker-compose up or docker-compose up -d to run the container on detached mode.
Compose will take some time to execute.
After the build has finished you can press the ctrl+c and docker-compose stop all containers.

Installing Magento

You will check the latest version of Magento from link: https://magento.com/tech-resources/download
To the run installation process use next commands.
Create new project:

./scripts/composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.6-p2 /home/magento

Install project:

./scripts/magento setup:install --base-url=http://magento2.test/ --db-host=mysql --db-name=magento_db --db-user=magento_user --db-password="PASSWD#" --admin-firstname=admin --admin-lastname=admin --admin-email=admin@admin.test --admin-user=admin --admin-password=admin1! --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --opensearch-host=opensearch --opensearch-port=9200

Setting up Magento

To access the magento homepage, go to the following url: http://magento2.test

Also, you can open:
http://mail.magento2.test - Mailhog
http://search.magento2.test - OpenSearch
http://dashboard.magento2.test - OpenSearch Dashboard
http://rabbit.magento2.test - RabbitMQ (guest/guest for access)

Feature Updates

  • v1.0.0 - Stable release
  • v1.0.1 - Updated to PHP 7.4.x, added docker-sync for MacOS users
  • v1.0.2 - Fix xDebug, add rabbitmq management, fix email sending
  • v1.0.3 - Updated to PHP 8.1.x
  • v1.0.4 - Fix xDebug for stable work
  • v1.0.5 - Replace Elasticsearch to OpenSearch, upgrade component versions, added varnish
  • v1.0.6 - Fix xDebug for correct stopping at point

Branches

  • master (for magento 2.4.6 and higher)
  • m244 (for magento 2.4.4 and higher till 2.4.6)