Business

How to Install Magento 2 on Docker? (Complete Step-by-Step Guide 2023)

If you’re having an Magento 2 based online store and want to scale your business then surely you’ve heard about Docker. It’s a platform that helps Magento 2 stores run more efficiently with add-on functionalities and scalability. It’s an easier version of magento 2 to set up your online store much faster and easily. 

The integration between Magento 2 and Docker makes the online store much more powerful and feature-rich. So if you want to install your Magento 2 online store on Docker then keep reading. 

Here, we will explore everything about Magento 2 Docker, its benefits and how you can set up a Magento 2 on docker with the help of Magento 2 Development Company. Let’s find out!

What is Docker?

Docker is an open-source software platform that helps you to build, run, update and deploy applications in packages called containers. These containers have all essential things a software requires including libraries, system, tools, code, runtime etc. The demand of docker increases when the world is shifting towards cloud-native development and hybrid environment. These containers are lightweight, portable and work in the same OS as the host machine. It supports all sizes of companies from startups to large enterprises.

Advantages of Using Docker

Here are some key advantages of using Docker for Magento 2:

1. Speed and Agility

One of the key benefits of using Docker is the speed and agility. It helps you to create containers for each process and deploy in seconds. This makes the overall process faster without booting the OS. The process of creating, destroying, starting or stopping containers becomes easier. With a configurable file such as YAML, you can automate the deployment and scalable infrastructure. Docker helps in increasing the speed and agility of your CI/CD pipelines by creating containers. 

2. Consistent Environment

It’s very essential that developers must get a consistent environment during the app designing, development, production to maintenance. It helps to understand the environment and eliminate the issue with a predictable environment where developers spend most of their time from building to development. It allows you to create specialized containers with predefined packages as per your needs. So that you can simply pull out the docker image and start working without any installation or configuration issues.

3. Security

Docker has a very secured environment where developers can run their applications in the containers safely. These docker containers can be isolated from each other and not able to check the processes running in other containers. Because each container comes with its own resources and doesn’t interact with other containers’ resources. So that it gains more control over the traffic.

4. Optimized Costs

Another major benefit of using docker is optimized costs. You need to consider ROI (return of investment) and docker allows you to reduce the infrastructure costs including employee strength to server costs. Docker allows developers to run the application at the minimal costs as compared to other technologies including VMs. It saves your operational costs and helps to drive high ROI.

5. Resource Efficiency

These containers required fewer resources as compared to virtual machines by sharing common underlying OS that leads to cost-efficient solutions.

6. Modular and Maintainable Applications

Docker support microservice architecture enables the development of modular applications with independent deployable services. It helps to do faster development and increase scalability for business growth.

How to Install Magento 2 on Docker?

Before start installing the Magento 2 on Docker, there are three common prerequisites that you must required such as:

1. Install Docker

The very first thing required to install Magento 2 on Docker is download and install the docker. You need to download docker based on your OS and install it.

2. Install Composer

Once you’ve downloaded and installed docker then it’s time to install composer. It is another essential thing that is required for installing Magento 2 on docker. It makes the process of installing plugins so easily accessible. It also helps in managing, installing packages and running additional scripts for each update.

3. Download Magento 2

Now, download the Magento 2 by following the given step-by-step process:

  • First, you need to access Mageplaza to download Magento 2.
  • Once you login, go to Access Keys and keep the window tab open.
  • Now, select the drive location where you want to save live files.
  • Open a command line terminal window and replace the placeholder path with final path by copying and pasting the below code:

cd /path/to/where/you/will/download/magento && \

composer create-project –repository-url=https://repo.magento.com/ 

magento/project-community-edition

  • Now, select the version you want to download and click on the Download button. 
  • You’ll be redirected to the directory where you can install the Magento. 
  • You need to increase the PHP memory limit from the default value of 765M to 2048M.
  • Then, select a domain name you would like to access and add it to your host’s file.

That’s all the prerequisites you required before starting installing the Magento 2 on Docker.

Now, Follow the step-by-step process to install Magento 2 on Docker by using magento upgrade services.

Step 1 – Generate a Docker-composer.yml File

  1. To install Magento 2 on Docker, first you need to select a place where you can put Docker Configuration Files. 

You can refer to this location (/path/to/docker).

  1. Next, open a new document.
  2. Copy the below code and paste 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

  1. Navigate to line 8 and replace the domain name with the created domain before.
  2. Then, replace /path/to/magento from line 17 to the Magento files you’ve downloaded before.
  3. Now, in step 1, save new files as /path/to/docker-compose.yml.

Step 2 – Start with Your Virtual Machine

  1. Now, you need to open your terminal to /path/to/docker.
  2. Start your virtual machine and take some minutes to let docker download the images. 
  3. Make sure that everything is set up and run according to the plan. Now, you need to go to 127.0.0.1.8080 in your web browser then you’ll see phpMyAdmin and then you can see it.

Step 3 – Install Magento 2 in detail

It’s time to install Magento 2 in detail:

  1. Access your command line that contains docker web: docker exec -it web bash
  2. Please go ahead to the web document root: cd / app
  3. It’s an optional but highly recommend step, deploy sample data: php bin/magento sampledata: deploy
  4. Now, install Magento 2, remember to copy and paste the following command into the decker terminal and don’t forget to replace the line from 2-6 with your own details and 7-8 with the placeholder domain.

php bin/magento setup:install \

–admin-firstname=John \

–admin-lastname=Doe \

–admin-email=johndoe@example.com \

–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

  1. Now, navigate to the website at https://local.domain.com or whatever the domain you’ve selected and spend some minutes to load the page to access the file for the first time. 

Also you may get a security alert when you’re visiting the URL for the first time.

Congratulations! you’ve successfully set up Magento 2 on Docker.

Wrapping Up!

Now, you can easily run Magento 2 on the Docker environment. We hope this guide makes the process easier and guides you with a step-by-step process to install Magento 2 on Docker. Now it’s your turn to hire a Magento 2 Development Company and follow the given steps to install it. 

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button