How to Setup Magento 2 on Docker
If you are searching “How to set up Magento 2 on Docker” or “Set up Magento 2 on Docker”, you come to the right post.
Magento 2 is one of the powerful open-source eCommerce platforms that is used to manage all store’s processes like shipping, billing, checkout, and more. Docker is a development environment platform using an operating system (OS). The integration of Magento 2 and Docker platforms will make your online store more powerful and flexible.
This post will show you a step-by-step guide on How to Set Up Magento 2 on Docker.
Without further ado, let’s jump right into the details!
Table of Contents
- Benefits of setting up Magento 2 on Docker
- How to Set up Magento 2 on Docker
- Final thoughts
Benefits of setting up Magento 2 on Docker
If you still wonder about Magento 2 and Docker integration, the following reasons can help you make a decision. Below are some fundamental reasons why you should set up Magento 2 on Docker.
- Magento 2 is a free environment, easy to develop and implement.
- Docker platform brings strong performance. Its portability and scalability are perfect for Magento 2 stores.
- You can be easy to use and install.
- You can set up Docker on your local machine and begin developing quickly.
- This platform is reliable, and it makes the development of Magento and PHP applications easier.
How to Set up Magento 2 on Docker
Some common prerequisites:
Obviously, the first step you have to do is to download and install Docker. Now the Docker platform is available on all operating systems. Whether you are using any operating system, you can also install and start it up.
In many different ways to install and manage Magento 2, Composer is the first preferred choice to set up. Because installing any plugin/ platform via Composer is always accessible and quick compared to other ways. Besides, Composer also enables you to manage and install packages, run additional scripts after each update.
Download Magento 2
To download Magento 2 for stores, please follow the guide below:
- You need to access Mageplaza to download Magento 2.
- After logging in, navigate to Access Keys, and this time, please keep that window open because the keys are necessary for step 3.
- Decide a location on your local machine that you want to put the website files to live.
- Please open a command line terminal window. Please replace the placeholder path with the final path where you will install Magento, before copying and pasting the code below.
cd /path/to/where/you/will/download/magento && \ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition
- Please choose the version you want and press the download button. Afterward, you will be redirected to the directory where you installed the Magento,
- At this point, please increase the PHP memory limit from the default value of 765M to 2048M.
- Finally, select a domain name that you would like to access the site, then add it to your host’s file.
sudo -- sh -c "echo '127.0.0.1 local.domain.com' >> /etc/hosts"
That’s all the prerequisites. Let’s explore 3 important steps !
Step 1: Generate a docker-composer.yml file
#1. You need to select a place to put your Docker configuration files. Refer this location as
#2. Next, open a new document.
#3. Now, click on “copy” and paste the following code into a new file:
version: '3' services: web: image: webdevops/php-apache-dev:ubuntu-16.04 container_name: web restart: always user: application environment: - WEB_ALIAS_DOMAIN=local.domain.com - WEB_DOCUMENT_ROOT=/app/pub - PHP_DATE_TIMEZONE=EST - PHP_DISPLAY_ERRORS=1 - PHP_MEMORY_LIMIT=2048M - PHP_MAX_EXECUTION_TIME=300 - PHP_POST_MAX_SIZE=500M - PHP_UPLOAD_MAX_FILESIZE=1024M volumes: - /path/to/magento:/app:cached ports: - "80:80" - "443:443" - "32823:22" links: - mysql mysql: image: mariadb:10 container_name: mysql restart: always ports: - "3306:3306" environment: - MYSQL_ROOT_PASSWORD=root - MYSQL_DATABASE=magento volumes: - db-data:/var/lib/mysql phpmyadmin: container_name: phpmyadmin restart: always image: phpmyadmin/phpmyadmin:latest environment: - MYSQL_ROOT_PASSWORD=root - PMA_USER=root - PMA_PASSWORD=root ports: - "8080:80" links: - mysql:db depends_on: - mysql volumes: db-data: external: false
#4. Navigate to line 8 and replace the domain name with the created domain before.
#5. On line 17, please replace /path/to/magento with the absolute path to the Magento files that you have downloaded before.
#6. Finally, in step 1, remember to save the new file as /path/to/docker/docker-compose.yml.
Step 2: Ready to start with your virtual machine
#1. In this step, you still need to open your terminal to /path/to/docker.
#2. It’s time to fire up your virtual machine. As soon as you spin up, it takes some minutes so that Dockers can download the images. After that, spin-ups in the future will take a few seconds.
docker-compose up -d --build
#3. Please make sure that everything is set up and run as per your plan. Then, you need to go to 127.0.0.1.8080 in your web browser, and you will see phpMyAdmin. Congrats, it’s successful if you can see it.
Step 3: Install Magento 2 in detail
It’s time to do the most important step. Let’s get going!
#1. Access your command line that contains your Docker web:
docker exec -it web bash
#2. Please go-ahead to the web document root:
#3. Although this is an optional step, highly recommended: deploy sample data:
php bin/magento sampledata:deploy
#4. Install Magento 2. Remember copying and pasting the following command into the Docker terminal. Note that you must replace the values on lines 2-6 with your own details. On lines 7-8, please replace the placeholder domain with your created domain name before.
php bin/magento setup:install \ --admin-firstname=John \ --admin-lastname=Doe \ [email protected] \ --admin-user=admin \ --admin-password='SomePassword123' \ --base-url=https://local.domain.com \ --base-url-secure=https://local.domain.com \ --backend-frontname=admin \ --db-host=mysql \ --db-name=magento \ --db-user=root \ --db-password=root \ --use-rewrites=1 \ --language=en_US \ --currency=USD \ --timezone=America/New_York \ --use-secure-admin=1 \ --admin-use-security-key=1 \ --session-save=files \ --use-sample-data
#5. Navigate to your website at
https://local.domain.com or whatever domain you select. You need to spend some minutes loading the page when you access the website for the first time. The reason for this is that nothing is cached and the Magento system will automatically create files when loading the pages. Don’t worry, as the loading process will be quicker next time.
Additionally, as the web container applies a self-signed SSL certificate, you can get a security alert from the browser when visiting the URL for the first time.
#6. Congratulations! You succeed in setting up Magento 2 on Docker. Please remember that you can repeat this process for other projects through our step-by-step guide.
That’s it! Now you have Magento 2 and run it on the Docker environment. It’s straightforward to follow if you spend more time reading this guide carefully. We wish that this article will help you install Magento 2 on Docker and of course, it will bring your Magento 2 store more great benefits afterward.
If you see our article as useful, don’t forget to share it with your friends as we will give you more helpful information in the next blog.
Thanks a lot for reading!
not your workload
Simple, powerful tools to grow your business. Easy to use, quick to master and all at an affordable price.Get Started