{"id":13632756,"url":"https://github.com/fballiano/docker-magento2","last_synced_at":"2025-04-23T14:17:57.644Z","repository":{"id":148249390,"uuid":"48171249","full_name":"fballiano/docker-magento2","owner":"fballiano","description":"Cluster ready Magento2 + Varnish 7 + PHP 8.1 + Redis 6.2 + Elasticsearch 7.17 + SSL","archived":false,"fork":false,"pushed_at":"2024-03-23T16:48:06.000Z","size":105,"stargazers_count":356,"open_issues_count":12,"forks_count":165,"subscribers_count":30,"default_branch":"M2.4.6","last_synced_at":"2025-04-23T14:17:52.528Z","etag":null,"topics":["docker","magento","magento2","redis"],"latest_commit_sha":null,"homepage":"","language":"VCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fballiano.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"fballiano","buy_me_a_coffee":"fballiano","custom":"https://paypal.me/fabrizioballiano"}},"created_at":"2015-12-17T11:44:13.000Z","updated_at":"2025-04-15T21:07:48.000Z","dependencies_parsed_at":"2024-08-01T22:41:34.129Z","dependency_job_id":"232ce8b5-aeb8-499d-a5d7-5029905559c2","html_url":"https://github.com/fballiano/docker-magento2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fballiano%2Fdocker-magento2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fballiano%2Fdocker-magento2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fballiano%2Fdocker-magento2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fballiano%2Fdocker-magento2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fballiano","download_url":"https://codeload.github.com/fballiano/docker-magento2/tar.gz/refs/heads/M2.4.6","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250447986,"owners_count":21432166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","magento","magento2","redis"],"created_at":"2024-08-01T22:03:14.838Z","updated_at":"2025-04-23T14:17:57.624Z","avatar_url":"https://github.com/fballiano.png","language":"VCL","funding_links":["https://github.com/sponsors/fballiano","https://buymeacoffee.com/fballiano","https://paypal.me/fabrizioballiano","https://www.buymeacoffee.com/fballiano","https://www.paypal.com/paypalme/fabrizioballiano"],"categories":["VCL","Open Source Extensions"],"sub_categories":["Infrastructure"],"readme":"# Docker Magento2: Varnish 7 + PHP 8.2 + Redis 6.2 + Elasticsearch 7.17 + SSL cluster ready docker-compose infrastructure\n\n\u003ctable\u003e\u003ctr\u003e\u003ctd align=center\u003e\n\u003cstrong\u003eIf you find my work valuable, please consider sponsoring\u003c/strong\u003e\u003cbr /\u003e\n\u003ca href=\"https://github.com/sponsors/fballiano\" target=_blank title=\"Sponsor me on GitHub\"\u003e\u003cimg src=\"https://img.shields.io/badge/sponsor-30363D?style=for-the-badge\u0026logo=GitHub-Sponsors\u0026logoColor=#white\" alt=\"Sponsor me on GitHub\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.buymeacoffee.com/fballiano\" target=_blank title=\"Buy me a coffee\"\u003e\u003cimg src=\"https://img.shields.io/badge/Buy_Me_A_Coffee-FFDD00?style=for-the-badge\u0026logo=buy-me-a-coffee\u0026logoColor=black\" alt=\"Buy me a coffee\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.paypal.com/paypalme/fabrizioballiano\" target=_blank title=\"Donate via PayPal\"\u003e\u003cimg src=\"https://img.shields.io/badge/PayPal-00457C?style=for-the-badge\u0026logo=paypal\u0026logoColor=white\" alt=\"Donate via PayPal\" /\u003e\u003c/a\u003e\n\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\n## Infrastructure overview\n* Container 1: Mysql 8.0\n* Container 2: Redis 7.0 (volatile, for Magento's cache)\n* Container 3: Redis 7.0 (for Magento's sessions)\n* Container 4: Apache 2.4 + PHP 8.2 (modphp)\n* Container 5: Cron\n* Container 6: Varnish 7.1\n* Container 7: Redis (volatile, cluster nodes autodiscovery)\n* Container 8: Nginx SSL terminator\n* Container 9: Elasticsearch 7.17\n\n### Why a separate cron container?\nFirst of all containers should be (as far as possible) single process, but the most important thing is that (if someday we'll be able to deploy this infrastructure in production) we may need a cluster of apache+php containers but a single cron container running.\n\nPlus, with this separation, in the context of a docker swarm, you may be able in the future to separare resources allocated to the cron container from the rest of the infrastructure.\n\n## Setup Magento 2\n\nDownload Magento 2 in any way you want (zip/tgz from website, composer, etc) and extract in the \"magento2\" subdirectory of this project.\n\nIf you want to change the default \"magento2\" directory simply change its name in the \"docker-compose.yml\" (there are 2 references, under the \"cron\" section and under the \"apache\" section).\n\n## Starting all docker containers\n```\ndocker-compose up -d\n```\nThe fist time you run this command it's gonna take some time to download all the required images from docker hub.\n\n## Install Magento2\n\n### Method 1: CLI\n```\ndocker exec -it docker-magento2-apache-1 bash\nphp bin/magento setup:install \\\n  --db-host docker-magento2-db-1 --db-name magento2 --db-user magento2 --db-password magento2  --admin-user admin --timezone 'Europe/Rome' --currency EUR --use-rewrites 1 --cleanup-database \\\n  --backend-frontname admin --admin-firstname AdminFirstName --admin-lastname AdminLastName --admin-email 'admin@email.com' --admin-password 'ChangeThisPassword1' --base-url 'https://magento2.docker/' --language en_US \\\n  --session-save=redis --session-save-redis-host=sessions --session-save-redis-port=6379 --session-save-redis-db=0 --session-save-redis-password='' \\\n  --cache-backend=redis --cache-backend-redis-server=cache --cache-backend-redis-port=6379 --cache-backend-redis-db=0 \\\n  --page-cache=redis --page-cache-redis-server=cache --page-cache-redis-port=6379 --page-cache-redis-db=1 \\\n  --search-engine=elasticsearch7 --elasticsearch-host=elasticsearch\n```\n\n## Deploy static files\n```\ndocker exec -it docker-magento2-apache-1 bash\nphp bin/magento dev:source-theme:deploy\nphp bin/magento setup:static-content:deploy\n```\n\n## Enable Varnish\nVarnish Full Page Cache should already be enabled out of the box (we startup Varnish with the default VCL file generated by Magento2) but you could anyway go to \"stores -\u003e configuration -\u003e advanced -\u003e system -\u003e full page cache\" and:\n* select Varnish in the \"caching application\" combobox\n* type \"apache\" in both \"access list\" and \"backend host\" fields\n* type 80 in the \"backend port\" field\n* save\n\nConfigure Magento to purge Varnish:\n\n```\ndocker exec -it docker-magento2_apache_1 bash\nphp bin/magento setup:config:set --http-cache-hosts=varnish\n```\n\nhttps://devdocs.magento.com/guides/v2.3/config-guide/varnish/use-varnish-cache.html\n\n## Enable SSL Support\nAdd this line to magento2/.htaccess\n```\nSetEnvIf X-Forwarded-Proto https HTTPS=on\n```\nThen you can configure Magento as you wish to support secure urls.\n\nIf you need to generate new self signed certificates use this command\n```\nopenssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt\n```\nthen you can mount them into the nginx-ssl container using the \"volumes\" instruction in the docker-compose.xml file. Same thing goes if you need to use custom nginx configurations (you can mount them into /etc/nginx/conf.d). Check the source code of https://github.com/fballiano/docker-nginx-ssl-for-magento2 to better understand where are the configuration stored inside the image/container.\n\n## Scaling apache containers\nIf you need more horsepower you can\n```\ndocker-compose scale apache=X\n```\nwhere X is the number of apache containers you want.\n\nThe cron container will check how many apache containers we have (broadcast/discovery service is stored on the redis_clusterdata container) and will update Varnish's VCL.\n\nYou can start your system with just one apache container, then scale it afterward, autodiscovery will reconfigure the load balancing on the fly.\n\nAlso, the cron container (which updates Varnish's VCL) sets a \"probe\" to \"/fb_host_probe.txt\" every 5 seconds, if 1 fails (container has been shut down) the container is considered sick.\n\n## Custom php.ini\nWe already have a personalized php.ini inside this project: https://github.com/fballiano/docker-magento2-apache-php/blob/master/php.ini but if you want to further customize your settings:\n- edit the php.ini file in the root directoy of this project\n- edit the \"docker-compose.xml\" file, look for the 2 commented lines (under the \"cron\" section and under the \"apache\" section) referencing the php.ini\n- start/restart the docker stack\n\nPlease note that your php.ini will be the last parsed thus you can ovverride any setting.\n\n## Tested on:\n* Docker for Mac 19\n\n## TODO\n* DB clustering?\n* RabbitMQ?\nlet me know what features would you like to see implemented.\n\n## Changelog:\n* 2020-09-19:\n  * Magento 2.4 branch added\n  * Elasticsearch container added for Magento 2.4\n  * Upaded all dependencies\n* 2020-03-18:\n  * added \"sockets\" PHP extension to docker-apache-php image\n  * fixed some typos/mistakes in the README\n  * added CLI install to the README\n  * refactored some parts of the documentation to better use magento's CLI\n* 2019-08-09:\n  * small bugfix in varnishadm.sh and varnishncsa.sh scripts\n* 2019-08-06:\n  * new redis sessions container was added\n* 2019-08-05:\n  * migrated to docker-compose syntax 3.7\n  * implemented \"delegated\" consistency for some of volumes for a better performance\n  * varnish.vcl was regenerated for Varnish 5 (which was already used since some months)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffballiano%2Fdocker-magento2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffballiano%2Fdocker-magento2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffballiano%2Fdocker-magento2/lists"}