×



















    Get a Free Consultation

    Search for:

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

    Last Updated | May 3, 2024

    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!


    folio-social-logo
    About

    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.