|
| 1 | +# Magento2 dev docker |
| 2 | + |
| 3 | +A development docker for every magento2 project |
| 4 | + |
| 5 | + |
| 6 | +## Features |
| 7 | + |
| 8 | +- Build for magento2 projects |
| 9 | +- Bundle of `fpm`, `cli`, `nginx`, `mariadb`, `phpmyadmin`, `redis` , `elasticsearch`, `rabbitmq`, `emailcatcher` and `varnish` containers |
| 10 | +- Latest PHP versions |
| 11 | + - php7.4 (for Magento2.4.x - default) |
| 12 | +- Latest database mariadb10.4, mariadb10.2 and other versions supported |
| 13 | +- Latest node14.x, node13.x, node12.x, ... supported |
| 14 | +- Latest redis-6.x, redis-5.x, ... supported |
| 15 | +- Latest elasticsearch-7.9.x, elasticsearch-6.x, ... supported |
| 16 | +- Latest rabbitmq-3.8.x, ... supported |
| 17 | +- Latest varnish-6.4, varnish-6.0, ... supported |
| 18 | +- Included n98-magerun2, composer, node cli and yarn cli |
| 19 | +- Included emailcatcher with smtp and web view |
| 20 | +- Support for PhpStorm or VSCode + WSL2/docker-desktop setup |
| 21 | +- Support for xdebug included check `.env` file |
| 22 | + |
| 23 | + |
| 24 | +## Docker setup |
| 25 | + |
| 26 | +- `git clone https://github.com/readymadehost/magento2-dev-docker.git project-docker` |
| 27 | +- `cd project-docker` |
| 28 | +- `mkdir project` or `git clone <some_git_repo_url> project` for existing project |
| 29 | +- `cp .env.sample .env` and review `.env` file |
| 30 | +- `docker-compose build` |
| 31 | +- `docker-compose up -d` |
| 32 | +- `docker-compose exec cli bash` |
| 33 | +- `php -v && php -m` |
| 34 | + |
| 35 | + |
| 36 | +## New magento2 project install |
| 37 | + |
| 38 | +- Read https://devdocs.magento.com/guides/v2.4/install-gde/composer.html |
| 39 | +- `docker-compose exec cli bash` and make sure you are at `/var/www/project` dir |
| 40 | +- Setup new magento2 project using composer |
| 41 | + - `composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition .` |
| 42 | + - or `composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition .` |
| 43 | + - or `composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition={version} .` |
| 44 | +- Run bash alis `mpp` for `/root/manage-project-permission.sh` |
| 45 | +- Run `bin/magento` and should return list of commands |
| 46 | +- Magento2.4.x project install command https://devdocs.magento.com/guides/v2.4/install-gde/install/cli/install-cli.html |
| 47 | +- Setup sample data `bin/magento sampledata:deploy` |
| 48 | +- `bin/magento setup:upgrade` |
| 49 | +- Run bash alis `mpp` for `/root/manage-project-permission.sh` |
| 50 | + |
| 51 | +#### Install for Magento2.4.x |
| 52 | + |
| 53 | +``` |
| 54 | +bin/magento setup:install \ |
| 55 | +--base-url=http://localhost:8080 \ |
| 56 | +--db-host=mariadb \ |
| 57 | +--db-name=project \ |
| 58 | +--db-user=root \ |
| 59 | +--db-password=root \ |
| 60 | +--backend-frontname=admin \ |
| 61 | +--admin-firstname=admin \ |
| 62 | +--admin-lastname=admin \ |
| 63 | +--admin-email=admin@admin.com \ |
| 64 | +--admin-user=admin \ |
| 65 | +--admin-password=admin@123 \ |
| 66 | +--language=en_US \ |
| 67 | +--currency=USD \ |
| 68 | +--timezone=America/Chicago \ |
| 69 | +--use-rewrites=1 \ |
| 70 | +--search-engine=elasticsearch7 \ |
| 71 | +--elasticsearch-host=elasticsearch \ |
| 72 | +--elasticsearch-port=9200 |
| 73 | +``` |
| 74 | + |
| 75 | + |
| 76 | +## Notes |
| 77 | + |
| 78 | +- Magento2 project URL: http://{localhost/any_valid_host}:8080/ |
| 79 | +- PhpMyAdmin URL: http://{localhost/any_valid_host}:8081/ |
| 80 | +- Mailcatcher URL: http://{localhost/any_valid_host}:8082/ |
| 81 | +- Varnish URL: http://{localhost/any_valid_host}:8088/ |
| 82 | +- For more info and change, check `.env` and `docker-compose.yml` |
| 83 | +- Manage permission inside container using bash alias `mpp` or `/root/manage-project-permission.sh` |
| 84 | +- Mariadb default:- host: `mariadb` user: `root`, password: `root`, database: `project` |
| 85 | + |
| 86 | +```text |
| 87 | +- <docker_root_dir> <-- docker root dir |
| 88 | +- <docker_root_dir>/data <-- all docker data persist |
| 89 | +- <docker_root_dir>/nginx <-- nginx |
| 90 | +- <docker_root_dir>/php* <-- php cli and fpm containers |
| 91 | +- <docker_root_dir>/.env <-- docker environment configuration |
| 92 | +
|
| 93 | +- <docker_root_dir>/project <-- project root dir |
| 94 | +
|
| 95 | +- <docker_root_dir>/project* <-- added in .gitignore |
| 96 | +- <docker_root_dir>/*.sql <-- added in .gitignore |
| 97 | +``` |
| 98 | + |
| 99 | +## Elasticsearch support |
| 100 | + |
| 101 | +- mkdir data/elasticsearch |
| 102 | +- sudo chown -R 1000:1000 -R data/elasticsearch |
| 103 | + |
| 104 | +#### Elasticsearch container keeps stopping? Try followings:- |
| 105 | + |
| 106 | +#### Temp solution |
| 107 | + |
| 108 | +- sudo sysctl -w vm.max_map_count=262144 |
| 109 | + |
| 110 | +#### For debian host persistence |
| 111 | + |
| 112 | +- sudo vi /etc/sysctl.conf |
| 113 | +- add new line `vm.max_map_count=262144` |
| 114 | +- sudo sysctl -p |
| 115 | + |
| 116 | +#### For arch host persistence |
| 117 | + |
| 118 | +- sudo vim /usr/lib/sysctl.d/10-arch.conf |
| 119 | +- add new line vm.max_map_count=262144 |
| 120 | +- after reboot, it should persist |
| 121 | + |
| 122 | + |
| 123 | +## Mailcatcher support |
| 124 | + |
| 125 | +Mailcatcher service is included, can be accessed using URL and can be configured using smtp:- |
| 126 | + |
| 127 | +``` |
| 128 | +smtp://mailcatcher:1025 |
| 129 | +``` |
| 130 | + |
| 131 | + |
| 132 | +## Phpstorm setup |
| 133 | + |
| 134 | +Simply add remote docker-compose php cli interpreter (exec with docker-compose.yml), change path mapping and configure remote interpreter for composer, phpunit, phpcs, phpcbf, phpmd and php-cs-fixer. |
| 135 | + |
| 136 | + |
| 137 | +## Remote container extension + vscode |
| 138 | + |
| 139 | +With vscode's remote container extension, we can simply connect into cli container. |
| 140 | + |
| 141 | + |
| 142 | +## For development usages |
| 143 | + |
| 144 | +- Clone this repo and pull on update. ReadyMadeHost cli tool coming soon... |
| 145 | + |
| 146 | +## For production usages |
| 147 | + |
| 148 | +- Current docker setup is for development only. Planning for ReadyMadeHost coming soon... |
0 commit comments