Setting Up a Magento 2 Development Environment Using docker-magento

Learn how to use docker-magento to get a new Magento 2 development environment set up in minutes.

Mark Shust

Mark Shust

Last Updated 4 min read


When I first started developing in Magento 2 back in 2015, I faced tons of issues trying to install Magento locally on my machine. These difficulties led me down the path of Docker, a powerful tool that changed the way I set up Magento development projects.

In this article, I'll walk you through setting up a Magento 2 development environment quickly and easily using docker-magento, a popular GitHub repo that significantly simplifies the installation process. Let's dive right in!

What is Docker?

If you're unfamiliar with Docker, it's a type of virtualization process that packages your code into specific containers. Each container runs an isolated service, like PHP, Nginx, or MySQL. This isolation makes it easy to swap services, upgrade versions, and manage your development environment efficiently.

Docker has emerged as an incredibly powerful tool in the world of software development. Its clean, organized, and well-structured environment saves time and resources and prevents dependency conflicts, which could lead to unexpected bugs and headaches.

Advantages of Docker

Some key advantages of using Docker include:

  1. Streamlined setup and maintenance: Docker allows you to create specialized containers with predefined packages and dependencies tailored to your needs. While other team members can simply pull the relevant Docker image and start working without worrying about installation or configuration.

  2. Consistency across environments: Docker enables mirroring of development, staging, and production environments to prevent discrepancies and improve reliability during deployment.

  3. Resource efficiency: Containers consume fewer resources than virtual machines since they share a common underlying operating system, resulting in a more cost-effective and efficient solution.

  4. Modular and maintainable applications: Docker's support for microservice architecture enables the development of smaller, modular applications, with isolated and independently deployable services. This allows for faster development cycles and increased scalability for growing businesses.

Setting Up docker-magento

The GitHub Repo

The docker-magento repo is available at markshust/docker-magento. This repo has nearly 2,000 stars on GitHub, and its popularity is a testament to its usefulness.

Setup Process

Setting up docker-magento is easy. Create a new directory, navigate into it, and then run a single curl command found in the GitHub readme. You can customize the provided script by changing the default domain, the Magento version, and the type of Magento installation (community or enterprise).

For example, this command sets up a community edition Magento 2.4.6 instance with the domain m2.test:

curl -s | bash -s -- m2.test 2.4.6 community

Once executed, docker-magento takes care of the rest by booting and initializing the necessary containers and downloading all requirements for Magento.

Secure Certificates and Selective Sync

docker-magento requires a secure certificate, created through a local certificate authority chain. During the setup, you'll be prompted for your system password twice to complete the certificate generation.

The docker-magento repo also includes a Selective Sync setup to improve performance with large file systems on Docker. This technique, based on my volume mount approach for performance, selectively syncs only the required folders and files that need bi-directional communication, significantly increasing filesystem performance.

Installing Magento

Once the initial setup is complete, you'll get a URL to access your Magento instance. Magento 2.4.6, for instance, will be completely installed and accessible at https://m2.test.

To install sample data, run this command:

bin/magento sampledata:deploy

Additionally, to activate the sample data, run the following command:

bin/magento setup:upgrade

This installs the sample data to Magento's database, making learning and development easier.

Additional CLI Commands

The docker-magento repo includes a list of custom CLI commands found in the readme. These commands execute underlying Docker commands in the background, simplifying complexities and making the onboarding process easier for new developers.

This approach allows teams to utilize repeatable, proven scripts that are battle-tested during development, without having to learn all the Docker specifics, ensuring their development environments are on par with peer agencies.

Learn more about M2 dev environments

This is just a really brief overview of how to get up & running quickly with docker-magento.

For a full deep dive into setting up a Magento 2 development environment, check out my free Magento 2 Development Environment course.

Set Up a Magento 2 Development Environment with Docker

Join the 9,000+ students currently registered in this course, and learn how to set up a Magento 2 development environment using Docker, Nginx, PHP, MySQL, and Redis.

Wrapping It Up

docker-magento simplifies the Magento development environment setup process, taking care of all complexities and making onboarding easy for new developers.

If you have found docker-magento useful, please consider starring the GitHub repo ⭐️.

Excited to broaden your Magento horizon? Here are 3 solutions I can share to elevate your learning:

  1. The free Magento 2 Development Environment course (9,000+ students)
  2. Grow your Magento expertise with all courses & lessons (700+ students)
  3. Learn visually with blocks of code & inline comments (3,000+ students)