Skip to content

digitalspacestdio/homebrew-docker-compose-magento

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magento 2 Docker Compose Environment

The easy magento environment for Dummies Supported Systems

  • MacOs (Intel, Apple M1)
  • Linux (AMD64, ARM64)
  • Windows via WSL2 (AMD64)

Pre-requirements

Docker

MacOs
Install Docker for Mac: https://docs.docker.com/desktop/mac/install/

Linux
Install Docker with Compose plugin:

curl https://get.docker.com | sudo bash
sudo usermod -aG docker $USER
exec su -l $USER

Windows
Follow this guide: https://docs.docker.com/desktop/windows/wsl/

Homebrew (MacOs/Linux/Windows)

Install Homebrew by following guide https://brew.sh

Composer Credentials

You need to export COMPOSER_AUTH variable s othat Composer can use credentials inside containers

export COMPOSER_AUTH='{
    "http-basic": {
        "repo.magento.com": {
            "username": "xxxxxxxxxxxx",
            "password": "yyyyyyyyyyyy"
        }
    },
    "github-oauth": {
        "github.com": "xxxxxxxxxxxx"
    }
}'

You can get the value from local machine where composer already configure using following command:

echo "export COMPOSER_AUTH='"$(cat $(php -d display_errors=0 $(which composer) config --no-interaction --global home 2>/dev/null)/auth.json)"'"

Optionally you can add this row to your ~/.bashrc or ~/.zshrc

Installation

Install the formula via homebrew

brew install digitalspacestdio/docker-compose-magento/docker-compose-magento

Option.1 Starting new magento project with sample data from scratch

  1. Create the new projet directory
mkdir ~/magento2
  1. Navigate to the projet directory
cd ~/magento2
  1. Create the new magento project
docker-compose-magento composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=^2 /var/www
  1. Deploy sample data
docker-compose-magento bin/magento sampledata:deploy
  1. Install the application
docker-compose-magento bin/magento setup:install --backend-frontname="admin" --key="admin" --session-save="files" --db-host="database:3306" --db-name="magento2" --db-user="magento2" --db-password="magento2" --admin-user="admin" --admin-password='$ecretPassw0rd' --admin-email="[email protected]" --admin-firstname="John" --admin-lastname="Doe" --key="26765209cb05b93729898c892d18a8dd" --search-engine=elasticsearch7  --elasticsearch-host=elasticsearch --elasticsearch-port=9200 --base-url="http://localhost:30280/" --base-url-secure="https://localhost:30280/"
  1. Optionally: Disable 2FA module (if needed)
docker-compose-magento bin/magento module:disable Magento_TwoFactorAuth Magento_AdminAdobeImsTwoFactorAuth
  1. Optionally: Disable FPC
docker-compose-magento bin/magento cache:disable full_page
  1. Optionally: Disable Secure URLs
docker-compose-magento bin/magento config:set web/secure/use_in_adminhtml 0
docker-compose-magento bin/magento config:set web/secure/use_in_frontend 0
docker-compose-magento bin/magento cache:clean
  1. Start the stack in the background mode
docker-compose-magento up -d

Application will be available by following link: http://localhost:30280/

Option.2 Starting already exists project from git and local sql dump

  1. Clone the project source code
git clone https://github.com/magento/magento2.git ~/magento2
  1. navigate to the project dir
cd  ~/magento2
  1. Install dependencies
docker-compose-magento composer install -o --no-interaction
  1. Configure the application database credentials
docker-compose-magento bash -c 'bin/magento setup:config:set --quiet --db-host $DATABASE_HOST --db-user $DATABASE_USER --db-password $DATABASE_PASSWORD --db-name $DATABASE_NAME'
docker-compose-magento bin/magento app:config:import --quiet
  1. Configure the application redis settings
docker-compose-magento bin/magento setup:config:set --quiet --cache-backend redis --cache-backend-redis-server redis --cache-backend-redis-port 6379 --cache-backend-redis-db 0
docker-compose-magento bin/magento setup:config:set --quiet --session-save redis --session-save-redis-host redissession --session-save-redis-port 6379 --session-save-redis-db 0
docker-compose-magento bin/magento app:config:import --quiet
  1. Configure the application elasticsearch settings
docker-compose-magento bin/magento config:set catalog/search/elasticsearch7_server_hostname elasticsearch
docker-compose-magento bin/magento config:set catalog/search/elasticsearch7_server_port 9200
docker-compose-magento bin/magento app:config:import --quiet
  1. Import database dump (supports *.sql and *.sql.gz files)
docker-compose-magento database-import /path/to/dump.sql.gz
  1. Optionally: Disable 2FA module (if needed)
docker-compose-magento bin/magento module:disable Magento_TwoFactorAuth
  1. Optionally: Disable FPC
docker-compose-magento bin/magento cache:disable full_page
  1. Optionally: Disable Secure URLs
docker-compose-magento bin/magento config:set  web/secure/use_in_adminhtml 0
docker-compose-magento bin/magento config:set  web/secure/use_in_frontend 0
docker-compose-magento bin/magento cache:clean
  1. Start the stack in the background mode
docker-compose-magento up -d

or if you want to bind custom port

COMPOSE_PROJECT_PORT_HTTP=80 docker-compose-magento up -d

Application will be available by following link: http://localhost:30280/

Shutdown the project stack

Stop containers

docker-compose-magento down

Destroy containers and persistent data

docker-compose-magento down -v

Extra tools

Connecting to the mysql container

docker-compose-magento mysql

Connecting to the cli container

docker-compose-magento bash

Generate compose config and run directly without this tool

docker-compose-magento config > docker-compose.yml
docker compose up

Environment Variables

Can be stored in the .dockenv, .dockerenv or .env file in the project root

  • COMPOSE_PROJECT_MODE - (mutagen|default)
  • COMPOSE_PROJECT_COMPOSER_VERSION - (1|2 )
  • COMPOSE_PROJECT_PHP_VERSION - (7.4|8.0|8.1|8.2), the image will be built from a corresponding fpm-alpine image, see https://hub.docker.com/_/php/?tab=tags&page=1&name=fpm-alpine&ordering=name for more versions
  • COMPOSE_PROJECT_NODE_VERSION - (12.22.12|14.19.3|16.16.0) the image will be built from a corresponding alpine image, see https://hub.docker.com/_/node/tags?page=1&name=alpine3.16 for more versions
  • COMPOSE_PROJECT_MYSQL_IMAGE - mysql:8.0-oracle see https://hub.docker.com/_/mysql/?tab=tags for more versions
  • COMPOSE_PROJECT_ELASTICSEARCH_VERSION - 7.17.5 see https://www.docker.elastic.co/r/elasticsearch/elasticsearch-oss for more versions
  • COMPOSE_PROJECT_NAME - by default the working directory name will be used
  • COMPOSE_PROJECT_PORT_PREFIX - 302 by default
  • COMPOSE_PROJECT_PORT_HTTP - $COMPOSE_PROJECT_PORT_PREFIX + 80 by default
  • COMPOSE_PROJECT_PORT_XHGUI - $COMPOSE_PROJECT_PORT_PREFIX + 81 by default
  • COMPOSE_PROJECT_PORT_MYSQL - $COMPOSE_PROJECT_PORT_PREFIX + 06 by default
  • COMPOSE_PROJECT_PORT_ELASTICSEARCH - $COMPOSE_PROJECT_PORT_PREFIX + 92 by default
  • COMPOSE_PROJECT_PORT_MAIL_WEBGUI - $COMPOSE_PROJECT_PORT_PREFIX + 25 by default

Enable xdebug

In first you need to define the environment variable XDEBUG_MODE

export XDEBUG_MODE=debug

or container specific

export XDEBUG_MODE_FPM=debug
export XDEBUG_MODE_CLI=debug
export XDEBUG_MODE_CRON=debug

Visual Studio Code launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "hostname": "0.0.0.0",
            "port": 9003,
            "pathMappings": {
                "/var/www": "${fileWorkspaceFolder}"
            }
        }
    ]
}

Configure the XhProf in the project

Add required packages

docker-compose-magento composer require perftools/php-profiler 
docker-compose-magento composer require perftools/xhgui-collector
docker-compose-magento composer require alcaeus/mongo-php-adapter

Apply the patch

docker-compose-magento xhprof-patch

To revert the patch run:

docker-compose-magento xhprof-revert

About

The Docker Compose based standalone environment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published