Magento 2 Docker Setup Guide: Step-by-Step Instructions

Contact Us

×

Get a Free Consultation

Are you aiming to optimize your Magento 2 development environment using Docker? Docker offers a convenient method for managing Magento projects with isolated containers, simplifying setup and deployment. In this guide, we’ll walk you through the process of setting up Magento 2 Docker step by step.

Read Also: Magento 2 Customer Segmentation and Personalization – Guide

Step 1: Install Docker and Docker Compose

1. Docker: Install Docker by following the instructions provided on the official Docker website for your operating system.

2. Docker Compose: Docker Compose usually comes bundled with Docker Desktop for Windows and macOS. For Linux, you may need to install it separately.

Step 2: Create a Docker Compose File

Next, create a docker-compose.yml file in your Magento project directory. This file will define the services and configurations for your Magento Docker setup.

Here’s a basic example to get:

version: '3'

services:

  web:

    image: 'magento/magento-cloud-docker-php:7.4-fpm'

    ports:

      - '80:80'

    environment:

      - VIRTUAL_HOST=magento.local

    volumes:

      - .:/var/www/html

  db:

    image: mysql:5.7

    environment:

      - MYSQL_ROOT_PASSWORD=root_password

      - MYSQL_DATABASE=magento

      - MYSQL_USER=magento

      - MYSQL_PASSWORD=magento_password

    volumes:

      - db_data:/var/lib/mysql

volumes:

  Db_data:

Replace root_password, magento_password, and magento.local with your desired values.

Step 3: Set Up Hosts File (Optional)

Add an entry to your hosts file (/etc/hosts on Linux/macOS, C:\Windows\System32\drivers\etc\hosts on Windows) to map magento.local to 127.0.0.1.

127.0.0.1 magento.local

Step 4: Start Docker Containers

Navigate to your Magento project directory in the terminal and run:

docker-compose up -d

This command will start the Docker containers defined in your docker-compose.yml file in detached mode (-d flag).

Step 5: Install Magento 2

1. Access your Magento container’s shell:

docker-compose exec web bash

2. Navigate to the Magento installation directory:

d /var/www/html

3. Install Magento using Composer:

composer create-project –repository-url=https://repo.magento.com/magento/project-community-editionitio
.Follow the prompts to provide your Magento Marketplace credentials.

4. Set file permissions:

chmod -R 777 var/ generated/ pub/

Step 6: Complete Magento Installation

1. Open a web browser and navigate to http://magento.local.

2. Follow the on-screen instructions to complete the Magento installation, including database setup, admin account creation, and store configuration.

Step 7: Finalize Configuration

After Magento installation is complete, finalize any additional configurations such as enabling developer mode, setting up SSL certificates (if required), installing themes/extensions, etc.

That’s it! You’ve successfully set up Magento 2 with Docker. You can now start developing your Magento store within the Docker environment.

Read Also: How to solve the ‘too many redirects’ issue in Magento 2?

Conclusion

Setting up Magento 2 with Docker offers a flexible and efficient development environment. Docker containers isolate dependencies, easing management of multiple Magento projects and collaboration. By following this guide, you’ll quickly dive into Magento development using Docker.

Happy coding!

About Author

Picture of Syed Hassan Raza Rizvi

Syed Hassan Raza Rizvi

Hassan Raza is a seasoned SEO expert with over a decade of industry experience. Proficient in SEO, SEM, and digital marketing, he excels in driving online success for businesses. With a passion for writing about cutting-edge technology, AI trends, and eCommerce platforms such as Magento and BigCommerce, Hassan is a digital marketer by day and a tech enthusiast by night. His expertise and enthusiasm for digital trends make him a valuable asset in navigating the ever-evolving landscape of online marketing.

Table of Contents

Related Blogs

Magento Performance Optimization: 12 Proven Ways to Speed Up Your Store (2025)
Magento

Magento Performance Optimization: 12 Proven Ways to Speed Up Your Store (2025)

In today’s fast-paced e-commerce landscape, website speed directly impacts your bottom line—every second counts when customers browse your online store. If your Magento site takes too long to load, potential buyers will abandon their carts before completing purchases. Magento performance optimization has become essential for online retailers who want to stay competitive. Studies consistently show

Read More
Magento AI: Best Extensions, Tools & Trends to Grow Your Store in 2025
Magento

Magento AI: Best Extensions, Tools & Trends to Grow Your Store in 2025

The global AI market is set to reach $757.58 billion in 2025, with Generative AI spending projected to grow by 76.4%. For Magento (Adobe Commerce) stores processing over $155 billion in annual merchandise value, this isn’t just a trend—it’s a strategic imperative.  The question isn’t whether to adopt AI, but how to do it effectively.

Read More
Shopify Plus vs Magento 2: Complete 2025 Comparison Guide
Magento

Shopify Plus vs Magento 2: Complete 2025 Comparison Guide

Choosing between Shopify Plus vs Magento 2 can make or break your e-commerce success. Both platforms dominate the enterprise space, but they serve vastly different business needs. This guide breaks down the key differences to help you select the right platform for your online store in 2025. The e-commerce platform decision impacts everything: time to

Read More