{"id":24094,"date":"2026-02-03T12:49:48","date_gmt":"2026-02-03T12:49:48","guid":{"rendered":"https:\/\/ecommerce.folio3.com\/blog\/?p=24094"},"modified":"2026-02-20T08:50:49","modified_gmt":"2026-02-20T08:50:49","slug":"magento-2-docker-setup-guide","status":"publish","type":"post","link":"https:\/\/ecommerce.folio3.com\/blog\/magento-2-docker-setup-guide\/","title":{"rendered":"Magento 2 Docker Setup Guide: Step-by-Step Instructions"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Setting up a local Magento 2 development environment the traditional way is a time sink. PHP version conflicts, missing extensions, and database mismatches can eat hours before you write a single line of code.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">That&#8217;s exactly why the Magento 2 Docker approach has become the standard for development teams. This <a href=\"https:\/\/ecommerce.folio3.com\/blog\/magento-b2b-pricing\/\">guide walks you through the full Magento<\/a> 2 Docker setup \u2014 from installing Docker to running a working storefront \u2014 with practical configuration tips and common fixes along the way.<\/span><\/p>\n<h2><strong>Summary<\/strong><\/h2>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Why Docker is the preferred environment for Magento 2 development<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">System requirements and tools needed before you start<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">How to create and configure a <\/span><span style=\"font-weight: 400;\">docker-compose.yml<\/span><span style=\"font-weight: 400;\"> file for Magento<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Step-by-step container setup, Magento installation, and post-install configuration<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Common errors and how to resolve them quickly<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Performance and environment tips that competitors rarely cover<\/span><\/li>\n<\/ul>\n<h2><strong>Why Use Docker for Magento 2 Development?<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Before jumping into the Magento 2 Docker setup, it&#8217;s worth understanding why this approach beats a traditional LAMP\/WAMP stack.<\/span><\/p>\n<h3><strong>Isolated, Reproducible Environments<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">Docker containers package every dependency \u2014 PHP, MySQL, Nginx, Redis \u2014 into a self-contained unit. This means the environment on your machine matches your teammate&#8217;s and your staging server exactly. No more &#8220;it works on my machine&#8221; problems.<\/span><\/p>\n<h3><strong>Faster Onboarding for New Developers<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">A new developer can clone the project, run <\/span><span style=\"font-weight: 400;\">docker-compose up<\/span><span style=\"font-weight: 400;\">, and have a working Magento store running in under 15 minutes. Without Docker, that onboarding can take half a day.<\/span><\/p>\n<h3><strong>Multi-Project Management<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">Docker lets you run multiple Magento projects simultaneously on the same machine, each on isolated ports and databases. Switching between a Magento 2.4.6 and 2.4.7 project takes seconds. This flexibility is one reason Magento continues to hold its ground against enterprise SaaS platforms \u2014 if you&#8217;re evaluating whether Magento is the right platform before committing to a Docker-based development workflow, our<\/span><a href=\"https:\/\/ecommerce.folio3.com\/blog\/magento-vs-salesforce\/\"> <span style=\"font-weight: 400;\">Magento vs Salesforce Commerce Cloud comparison<\/span><\/a><span style=\"font-weight: 400;\"> breaks down the architecture, cost, and customization trade-offs in detail.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Traditional Setup<\/b><\/td>\n<td><b>Docker-Based Setup<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Manual PHP\/MySQL install per machine<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Defined once in docker-compose.yml<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Environment drift between team members<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Identical environments guaranteed<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Port conflicts between projects<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Each project runs on isolated ports<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Slow onboarding (hours)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Fast onboarding (minutes)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><strong>System Requirements and Prerequisites<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Make sure you have the following before starting the <a href=\"https:\/\/ecommerce.folio3.com\/blog\/zendesk-magento-integration\/\">Magento 2 Docker setup guide<\/a>. It&#8217;s also worth noting that Docker works specifically with Magento&#8217;s PHP-based open-source architecture \u2014 a key technical differentiator when comparing it to lighter-weight platforms. If you&#8217;re still evaluating Magento against other open-source options, the<\/span><a href=\"https:\/\/ecommerce.folio3.com\/blog\/magento-vs-nopcommerce\/\"> <span style=\"font-weight: 400;\">nopCommerce vs Magento breakdown<\/span><\/a><span style=\"font-weight: 400;\"> covers the platform differences in scalability, customization depth, and total cost of ownership.<\/span><\/p>\n<h3><strong>What You Need Installed<\/strong><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Docker Desktop<\/b><span style=\"font-weight: 400;\"> (Windows\/macOS) or <\/span><b>Docker Engine<\/b><span style=\"font-weight: 400;\"> (Linux) \u2014 version 20.x or later<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Docker Compose<\/b><span style=\"font-weight: 400;\"> \u2014 v2.x recommended (bundled with Docker Desktop)<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Git<\/b><span style=\"font-weight: 400;\"> \u2014 for cloning repositories<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Composer<\/b><span style=\"font-weight: 400;\"> \u2014 for Magento dependency management<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Magento Marketplace credentials<\/b><span style=\"font-weight: 400;\"> \u2014 you&#8217;ll need an access key (public + private) from<\/span><a href=\"https:\/\/marketplace.magento.com\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">marketplace.magento.com<\/span><\/a><\/li>\n<\/ul>\n<h3><strong>Minimum Hardware Recommendations<\/strong><\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Resource<\/b><\/td>\n<td><b>Minimum<\/b><\/td>\n<td><b>Recommended<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">RAM<\/span><\/td>\n<td><span style=\"font-weight: 400;\">4 GB<\/span><\/td>\n<td><span style=\"font-weight: 400;\">8 GB+<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Disk Space<\/span><\/td>\n<td><span style=\"font-weight: 400;\">20 GB free<\/span><\/td>\n<td><span style=\"font-weight: 400;\">40 GB+<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">CPU Cores<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">4+<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">OS<\/span><\/td>\n<td><span style=\"font-weight: 400;\">macOS 12+, Windows 10+, Ubuntu 20+<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Latest stable versions<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">If you&#8217;re running on macOS with Apple Silicon (M1\/M2\/M3), use Docker Desktop 4.x or later \u2014 it includes Rosetta 2 support and works well with Magento&#8217;s PHP images.<\/span><\/p>\n<h2><strong>Step 1: Install Docker and Docker Compose<\/strong><\/h2>\n<h3><strong>Installing Docker<\/strong><\/h3>\n<p><strong>Go to<a href=\"https:\/\/www.docker.com\/get-started\" target=\"_blank\" rel=\"noopener\"> docker.com\/get-started<\/a> and download Docker Desktop for your OS. On Linux, install Docker Engine via your package manager:<\/strong><\/p>\n<pre><span style=\"font-weight: 400;\">bash<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo<\/span> <span style=\"font-weight: 400;\">apt-get<\/span><span style=\"font-weight: 400;\"> update<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo<\/span> <span style=\"font-weight: 400;\">apt-get<\/span> <span style=\"font-weight: 400;\">install<\/span><span style=\"font-weight: 400;\"> docker-ce docker-ce-cli containerd.io docker-compose-plugin<\/span>\r\n\r\n<span style=\"font-weight: 400;\">After installation, verify it works:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">bash<\/span>\r\n\r\n<span style=\"font-weight: 400;\">docker<\/span><span style=\"font-weight: 400;\"> --version<\/span>\r\n\r\n<span style=\"font-weight: 400;\">docker<\/span><span style=\"font-weight: 400;\"> compose version<\/span><\/pre>\n<h3><strong>Enabling Required Resources<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">In Docker Desktop, go to <\/span><b>Settings &gt; Resources<\/b><span style=\"font-weight: 400;\"> and allocate at least 4 GB RAM and 4 CPUs. Magento 2 is resource-heavy, especially during compilation and indexing. Under-allocating is the number one cause of slow containers and failed installs.<\/span><\/p>\n<h2><strong>Step 2: Create the Project Directory and Docker Compose File<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">This is the core of your Magento 2 Docker setup. The <\/span><span style=\"font-weight: 400;\">docker-compose.yml<\/span><span style=\"font-weight: 400;\"> file defines every service your store needs.<\/span><\/p>\n<h3><strong>Setting Up the Project Folder<\/strong><\/h3>\n<pre><span style=\"font-weight: 400;\">bash<\/span>\r\n\r\n<span style=\"font-weight: 400;\">mkdir<\/span><span style=\"font-weight: 400;\"> magento2-docker &amp;&amp; <\/span><span style=\"font-weight: 400;\">cd<\/span><span style=\"font-weight: 400;\"> magento2-docker<\/span><\/pre>\n<h3><strong>The Docker Compose Configuration<\/strong><\/h3>\n<p><strong>Create a docker-compose.yml file in the project root with the following content:<\/strong><\/p>\n<pre><span style=\"font-weight: 400;\">yaml<\/span>\r\n\r\n<span style=\"font-weight: 400;\">version<\/span><span style=\"font-weight: 400;\">:<\/span> <span style=\"font-weight: 400;\">'3.8'<\/span>\r\n\r\n<span style=\"font-weight: 400;\">services<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">web<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">image<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> magento\/magento<\/span><span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\">cloud<\/span><span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\">docker<\/span><span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\">php<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\">8.2<\/span><span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\">fpm<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ports<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-<\/span> <span style=\"font-weight: 400;\">'80:80'<\/span>\r\n\r\n<span style=\"font-weight: 400;\">environment<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\"> VIRTUAL_HOST=magento.local<\/span>\r\n\r\n<span style=\"font-weight: 400;\">volumes<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\"> .<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\">\/var\/www\/html<\/span>\r\n\r\n<span style=\"font-weight: 400;\">depends_on<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\"> db<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\"> redis<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">db<\/span><span style=\"font-weight: 400;\">:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">image<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> mysql<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\">8.0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">environment<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\"> MYSQL_ROOT_PASSWORD=root_password<\/span>\u00a0\u00a0\r\n\r\n<span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\"> MYSQL_DATABASE=magento<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\"> MYSQL_USER=magento<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\"> MYSQL_PASSWORD=magento_password<\/span>\r\n\r\n<span style=\"font-weight: 400;\">volumes<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\"> db_data<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\">\/var\/lib\/mysql<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">redis<\/span><span style=\"font-weight: 400;\">:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">image<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> redis<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\">7.0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ports<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-<\/span> <span style=\"font-weight: 400;\">'6379:6379'<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">elasticsearch<\/span><span style=\"font-weight: 400;\">:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">image<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> elasticsearch<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\">7.17.0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">environment<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\"> discovery.type=single<\/span><span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\">node<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\"> ES_JAVA_OPTS=<\/span><span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\">Xms512m <\/span><span style=\"font-weight: 400;\">-<\/span><span style=\"font-weight: 400;\">Xmx512m<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ports<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-<\/span> <span style=\"font-weight: 400;\">'9200:9200'<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">volumes<\/span><span style=\"font-weight: 400;\">:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">db_data<\/span><span style=\"font-weight: 400;\">:<\/span><\/pre>\n<p><b>Why Elasticsearch?<\/b><span style=\"font-weight: 400;\"> Magento 2.4.x requires Elasticsearch (or OpenSearch) as its search engine. Skipping this service causes installation errors during catalog setup.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now that the services are defined, the next step is pointing your local domain to the container.<\/span><\/p>\n<h2><strong>Step 3: Configure the Hosts File<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Add a local domain entry so your browser can reach the Magento container.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Linux\/macOS:<\/b><span style=\"font-weight: 400;\"> Edit <\/span><span style=\"font-weight: 400;\">\/etc\/hosts<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Windows:<\/b><span style=\"font-weight: 400;\"> Edit <\/span><span style=\"font-weight: 400;\">C:\\Windows\\System32\\drivers\\etc\\hosts<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Add this line:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">127.0.0.1 magento.local<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Save the file. You may need admin\/sudo privileges to do this.<\/span><\/p>\n<h2><strong>Step 4: Start the Docker Containers<\/strong><\/h2>\n<p><strong>Navigate to your project directory and run:<\/strong><\/p>\n<pre><span style=\"font-weight: 400;\">bash<\/span>\r\n\r\n<span style=\"font-weight: 400;\">docker<\/span><span style=\"font-weight: 400;\"> compose up -d<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">The <\/span><span style=\"font-weight: 400;\">-d<\/span><span style=\"font-weight: 400;\"> flag runs containers in detached mode (background). The first run will pull Docker images, which may take a few minutes depending on your connection speed.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Check that all services are running:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">bash<\/span>\r\n\r\n<span style=\"font-weight: 400;\">docker<\/span><span style=\"font-weight: 400;\"> compose <\/span><span style=\"font-weight: 400;\">ps<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">You should see <\/span><span style=\"font-weight: 400;\">web<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">db<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">redis<\/span><span style=\"font-weight: 400;\">, and <\/span><span style=\"font-weight: 400;\">elasticsearch<\/span><span style=\"font-weight: 400;\"> listed as running.<\/span><\/p>\n<h2><strong>Step 5: Install Magento 2 Inside the Container<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">This is the most involved step of the Magento 2 Docker setup guide. You&#8217;ll install Magento using Composer inside the web container.<\/span><\/p>\n<h3><strong>Access the Web Container Shell<\/strong><\/h3>\n<pre>bash\r\n\r\ndocker compose exec web bash<\/pre>\n<h3><strong>Install Magento via Composer<\/strong><\/h3>\n<pre><span style=\"font-weight: 400;\">bash<\/span>\r\n\r\n<span style=\"font-weight: 400;\">composer<\/span><span style=\"font-weight: 400;\"> create-project --repository-url=https:\/\/repo.magento.com\/ <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">magento\/project-community-edition=<\/span><span style=\"font-weight: 400;\">2.4<\/span><span style=\"font-weight: 400;\">.7 \/var\/www\/html<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">When prompted, enter your Magento Marketplace public key as the username and your private key as the password.<\/span><\/p>\n<h3><strong>Set Correct File Permissions<\/strong><\/h3>\n<pre><span style=\"font-weight: 400;\">bash<\/span>\r\n\r\n<span style=\"font-weight: 400;\">find<\/span><span style=\"font-weight: 400;\"> \/var\/www\/html -type f -exec <\/span><span style=\"font-weight: 400;\">chmod<\/span> <span style=\"font-weight: 400;\">644<\/span> <span style=\"font-weight: 400;\">{}<\/span> <span style=\"font-weight: 400;\">\\;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">find<\/span><span style=\"font-weight: 400;\"> \/var\/www\/html -type d -exec <\/span><span style=\"font-weight: 400;\">chmod<\/span> <span style=\"font-weight: 400;\">755<\/span> <span style=\"font-weight: 400;\">{}<\/span> <span style=\"font-weight: 400;\">\\;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">chmod<\/span><span style=\"font-weight: 400;\"> -R <\/span><span style=\"font-weight: 400;\">777<\/span><span style=\"font-weight: 400;\"> \/var\/www\/html\/var \/var\/www\/html\/generated \/var\/www\/html\/pub\/static \/var\/www\/html\/pub\/media<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Avoid blanket <\/span><span style=\"font-weight: 400;\">777<\/span><span style=\"font-weight: 400;\"> permissions in production. They are fine for local Docker development but should never go to a live server.<\/span><\/p>\n<h2><strong>Step 6: Run the Magento 2 Installation Command<\/strong><\/h2>\n<p><strong>Instead of using the web-based installer, run the CLI installer for a faster, more reliable setup:<\/strong><\/p>\n<pre><span style=\"font-weight: 400;\">bash<\/span>\r\n\r\n<span style=\"font-weight: 400;\">php bin\/magento setup:install <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--base-url=http:\/\/magento.local\/ <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--db-host=db <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--db-name=magento <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--db-user=magento <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--db-password=magento_password <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--admin-firstname=Admin <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--admin-lastname=User <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--admin-email=admin@example.com <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--admin-user=admin <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--admin-password=Admin123! <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--language=en_US <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--currency=USD <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--timezone=America\/Chicago <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--use-rewrites=<\/span><span style=\"font-weight: 400;\">1<\/span> <span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--search-engine=elasticsearch7 <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--elasticsearch-host=elasticsearch <\/span><span style=\"font-weight: 400;\">\\<\/span>\r\n\r\n<span style=\"font-weight: 400;\">--elasticsearch-port=<\/span><span style=\"font-weight: 400;\">9200<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">The <\/span><span style=\"font-weight: 400;\">&#8211;db-host=db<\/span><span style=\"font-weight: 400;\"> matches the service name in your <\/span><span style=\"font-weight: 400;\">docker-compose.yml<\/span><span style=\"font-weight: 400;\">. Magento containers communicate by service name, not IP address.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>CLI Parameter<\/b><\/td>\n<td><b>Value<\/b><\/td>\n<td><b>Notes<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">&#8211;db-host<\/span><\/td>\n<td><span style=\"font-weight: 400;\">db<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Must match docker-compose service name<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">&#8211;search-engine<\/span><\/td>\n<td><span style=\"font-weight: 400;\">elasticsearch7<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Required for Magento 2.4.x<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">&#8211;elasticsearch-host<\/span><\/td>\n<td><span style=\"font-weight: 400;\">elasticsearch<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Must match service name<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">&#8211;use-rewrites<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Enables clean URLs<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><strong>Step 7: Post-Installation Configuration<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">With Magento installed, a few final steps will get your environment production-ready for development.<\/span><\/p>\n<h3><strong>Enable Developer Mode<\/strong><\/h3>\n<pre><span style=\"font-weight: 400;\">bash<\/span>\r\n\r\n<span style=\"font-weight: 400;\">php bin\/magento deploy:mode:set developer<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Developer mode disables caching and shows full error details \u2014 exactly what you need when building or debugging.<\/span><\/p>\n<h3><strong>Flush Cache and Run Indexers<\/strong><\/h3>\n<pre><span style=\"font-weight: 400;\">bash<\/span>\r\n\r\n<span style=\"font-weight: 400;\">php bin\/magento cache:flush<\/span>\r\n\r\n<span style=\"font-weight: 400;\">php bin\/magento indexer:reindex<\/span><\/pre>\n<h3><strong>Access the Storefront and Admin<\/strong><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Storefront:<\/b> <span style=\"font-weight: 400;\">http:\/\/magento.local<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Admin panel:<\/b> <span style=\"font-weight: 400;\">http:\/\/magento.local\/admin<\/span><span style=\"font-weight: 400;\"> (use the credentials you set during install)<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">If you see a blank page or 404, check that your hosts file entry is saved and the containers are all running.<\/span><\/p>\n<h3><strong>Configure Redis as the Cache Backend (Optional but Recommended)<\/strong><\/h3>\n<p><strong>Redis dramatically speeds up Magento&#8217;s cache response. Add the following to app\/etc\/env.php:<\/strong><\/p>\n<pre><span style=\"font-weight: 400;\">php<\/span>\r\n\r\n<span style=\"font-weight: 400;\">'cache'<\/span><span style=\"font-weight: 400;\"> =&gt; <\/span><span style=\"font-weight: 400;\">[<\/span>\r\n\r\n<span style=\"font-weight: 400;\">'frontend'<\/span><span style=\"font-weight: 400;\"> =&gt; <\/span><span style=\"font-weight: 400;\">[<\/span>\r\n\r\n<span style=\"font-weight: 400;\">'default'<\/span><span style=\"font-weight: 400;\"> =&gt; <\/span><span style=\"font-weight: 400;\">[<\/span>\r\n\r\n<span style=\"font-weight: 400;\">'backend'<\/span><span style=\"font-weight: 400;\"> =&gt; <\/span><span style=\"font-weight: 400;\">'Cm_Cache_Backend_Redis'<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n\r\n<span style=\"font-weight: 400;\">'backend_options'<\/span><span style=\"font-weight: 400;\"> =&gt; <\/span><span style=\"font-weight: 400;\">[<\/span>\r\n\r\n<span style=\"font-weight: 400;\">'server'<\/span><span style=\"font-weight: 400;\"> =&gt; <\/span><span style=\"font-weight: 400;\">'redis'<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n\r\n<span style=\"font-weight: 400;\">'port'<\/span><span style=\"font-weight: 400;\"> =&gt; <\/span><span style=\"font-weight: 400;\">'6379'<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n\r\n<span style=\"font-weight: 400;\">],<\/span>\r\n\r\n<span style=\"font-weight: 400;\">],<\/span>\r\n\r\n<span style=\"font-weight: 400;\">],<\/span>\r\n\r\n<span style=\"font-weight: 400;\">],<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">This is one configuration step most Magento 2 Docker setup guides skip \u2014 but it makes a real difference in page load times during development.<\/span><\/p>\n<h2><strong>Common Errors and Fixes<\/strong><\/h2>\n<table>\n<tbody>\n<tr>\n<td><b>Error<\/b><\/td>\n<td><b>Likely Cause<\/b><\/td>\n<td><b>Fix<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Connection refused<\/span><span style=\"font-weight: 400;\"> on port 3306<\/span><\/td>\n<td><span style=\"font-weight: 400;\">DB container not ready<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Wait 10\u201315s and retry, or add <\/span><span style=\"font-weight: 400;\">healthcheck<\/span><span style=\"font-weight: 400;\"> to compose<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Elasticsearch not available<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Wrong host or port<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Confirm <\/span><span style=\"font-weight: 400;\">&#8211;elasticsearch-host=elasticsearch<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Permission denied<\/span><span style=\"font-weight: 400;\"> on var\/ or pub\/<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Wrong file permissions<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Re-run the <\/span><span style=\"font-weight: 400;\">chmod 777<\/span><span style=\"font-weight: 400;\"> commands inside the container<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Blank storefront page<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Cache not flushed<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Run <\/span><span style=\"font-weight: 400;\">php bin\/magento cache:flush<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Composer auth error<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Wrong Marketplace keys<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Re-enter public\/private keys or update <\/span><span style=\"font-weight: 400;\">auth.json<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">If you&#8217;re managing a live <a href=\"https:\/\/ecommerce.folio3.com\/blog\/magento-gdpr\/\">Magento store<\/a> and need help beyond local development, Folio3&#8217;s<\/span><a href=\"https:\/\/ecommerce.folio3.com\/magento\/\"> <span style=\"font-weight: 400;\">Magento development services<\/span><\/a><span style=\"font-weight: 400;\"> cover everything from architecture to ongoing optimization. And if your team is weighing Magento against enterprise-grade alternatives at the platform level, the<\/span><a href=\"https:\/\/ecommerce.folio3.com\/blog\/magento-vs-oracle-commerce\/\"> <span style=\"font-weight: 400;\">Magento vs Oracle Commerce comparison<\/span><\/a><span style=\"font-weight: 400;\"> is a useful reference \u2014 it covers deployment models, infrastructure ownership, and cost structures that directly affect how you architect your development environment.<\/span><\/p>\n<h2><strong>Key Takeaways<\/strong><\/h2>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Docker eliminates environment inconsistency \u2014 every developer gets the same setup from a single config file.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Magento 2.4.x requires Elasticsearch or OpenSearch; skipping it breaks the install.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use the CLI installer (<\/span><span style=\"font-weight: 400;\">setup:install<\/span><span style=\"font-weight: 400;\">) over the web wizard for speed and reliability.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Redis as a cache backend meaningfully improves development environment performance.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Permission errors and container startup timing cause 80% of Docker setup failures \u2014 address those first.<\/span><\/li>\n<\/ul>\n<h2><strong>Frequently Asked Questions<\/strong><\/h2>\n<h3><strong>What Is the Best Docker Image for Magento 2 Docker Setup?<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">The official <\/span><span style=\"font-weight: 400;\">magento\/magento-cloud-docker-php<\/span><span style=\"font-weight: 400;\"> images are the most reliable starting point. For Magento 2.4.7, use the PHP 8.2-fpm variant. Community images like <\/span><span style=\"font-weight: 400;\">markoshust\/magento-nginx<\/span><span style=\"font-weight: 400;\"> are also widely used and well-maintained for local development.<\/span><\/p>\n<h3><strong>Does Magento 2 Docker Setup Work on Windows?<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">Yes. Use Docker Desktop with the WSL 2 backend enabled. Performance is significantly better with WSL 2 than with Hyper-V, especially for file I\/O-heavy Magento operations. Mount your project inside the WSL 2 filesystem rather than the Windows filesystem for best results.<\/span><\/p>\n<h3><strong>Which PHP Version Should I Use for Magento 2 Docker?<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">Magento 2.4.7 supports PHP 8.1 and 8.2. Use PHP 8.2-fpm for the latest compatibility. Check the<\/span><a href=\"https:\/\/experienceleague.adobe.com\/docs\/commerce-operations\/installation-guide\/system-requirements.html\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">Magento system requirements<\/span><\/a><span style=\"font-weight: 400;\"> page to confirm the version matrix for your specific Magento release.<\/span><\/p>\n<h3><strong>How Do I Add SSL to a Magento 2 Docker Environment?<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">For local development, use a tool like <\/span><span style=\"font-weight: 400;\">mkcert<\/span><span style=\"font-weight: 400;\"> to generate a locally-trusted SSL certificate. Add an Nginx container to your <\/span><span style=\"font-weight: 400;\">docker-compose.yml<\/span><span style=\"font-weight: 400;\"> configured to terminate SSL, then update your <\/span><span style=\"font-weight: 400;\">&#8211;base-url-secure<\/span><span style=\"font-weight: 400;\"> parameter during install. Most local dev environments skip SSL, but it&#8217;s useful if testing <a href=\"https:\/\/ecommerce.folio3.com\/blog\/magento-2-payment-gateways\/\">payment gateways<\/a>.<\/span><\/p>\n<h3><strong>How Does Magento 2 Docker Setup Compare to Warden or DDEV?<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">Warden and DDEV are pre-configured Docker toolkits that handle the full Magento 2 Docker setup automatically \u2014 Nginx, PHP, MySQL, Redis, Elasticsearch, and SSL are all pre-wired. If you want full control over your environment, a custom <\/span><span style=\"font-weight: 400;\">docker-compose.yml<\/span><span style=\"font-weight: 400;\"> is better. If you want a working store in under five minutes with no manual config, DDEV or Warden are faster.<\/span><\/p>\n<h3><strong>Can I Use This Setup for a Magento 2 Production Environment?<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">No. This guide is for local development. Production deployments require proper security hardening, HTTPS configuration, restricted file permissions, and optimized PHP-FPM pool settings. Review the<\/span><a href=\"https:\/\/experienceleague.adobe.com\/docs\/commerce-operations\/implementation-playbook\/best-practices\/deployment\/overview.html\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">Magento deployment best practices<\/span><\/a><span style=\"font-weight: 400;\"> for production guidance.<\/span><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">A proper Magento 2 Docker setup solves the environment consistency problem that slows down most development teams. By containerizing PHP, MySQL, Redis, and Elasticsearch, you get a reproducible, portable environment that works the same way for every developer on the team.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Follow this Magento 2 Docker setup guide from start to finish, and you&#8217;ll have a fully functional store running locally \u2014 with the right services, correct permissions, and performance configurations in place. If you&#8217;re planning to scale that store or need expert hands-on help with your Magento infrastructure,<\/span><a href=\"https:\/\/ecommerce.folio3.com\/contact-us\/\"> <span style=\"font-weight: 400;\">talk to Folio3&#8217;s Magento team<\/span><\/a><span style=\"font-weight: 400;\"> to see how we can help.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting up a local Magento 2 development environment the traditional way is a time sink. PHP version conflicts, missing extensions, and database mismatches can eat hours before you write a single line of code. That&#8217;s exactly why the Magento 2 Docker approach has become the standard for development teams. This guide walks you through the<\/p>\n","protected":false},"author":40,"featured_media":24095,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[27],"tags":[314],"class_list":{"0":"post-24094","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-magento","8":"tag-magento-2-docker-setup"},"acf":[],"featured_image_data":{"src":"https:\/\/ecommerce.folio3.com\/blog\/wp-content\/uploads\/2024\/05\/11817501_4851627.jpg","alt":"Magento 2 Docker Setup","caption":""},"_links":{"self":[{"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/posts\/24094"}],"collection":[{"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/comments?post=24094"}],"version-history":[{"count":0,"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/posts\/24094\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/media\/24095"}],"wp:attachment":[{"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/media?parent=24094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/categories?post=24094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/tags?post=24094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}