---
title: How to setup Docker Container for Magento 2
description: Docker container is the bundle of all the resources required to run your application in an isolated process. Read this blog to get the step-by-step process for Docker installation in Magento 2.
image: https://blog.e-zest.com/hubfs/How%20to%20setup%20Docker%20Container%20for%20Magento%202.jpg
---

[![e-Zest logo\_An accion lab company\_Colour](https://blog.e-zest.com/hubfs/images/Logos%20with%20Tagline/Corporate/SVG/e-Zest%20logo_An%20accion%20lab%20company_Colour.svg "e-Zest logo_An accion lab company_Colour")](https://www.e-zest.com/)

- [WORK](https://www.e-zest.com/our-work)
- [SERVICES](https://www.e-zest.com/our-services) 
    - [Product Engineering](https://www.e-zest.com/digital-product-engineering-services)
    - [Enterprise Data Services](https://www.e-zest.com/enterprise-data-services)
    - [Digital Commerce](https://www.e-zest.com/digital-commerce-services)
    - [Digital Operations](https://www.e-zest.com/digital-operations)
    - [Digital Consulting](https://www.e-zest.com/digital-transformation-consulting-services)
    - [Digital Experience Design](https://www.e-zest.com/digital-experience-design)
- [INSIGHTS](https://blog.e-zest.com/)
- [CAREERS](https://www.e-zest.com/careers)
- [ENTERPRISE DATA SERVICES](https://www.e-zest.com/enterprise-data-services)
- [GENERATIVE AI](https://www.e-zest.com/generative-ai)
- [Healthcare](https://healthcare.e-zest.com)
- [Contact Us](https://www.e-zest.com/contact-us)

- ![Elevating Product Engineering with AI and ML](https://blog.e-zest.com/hubfs/Elevating%20Product%20Engineering%20with%20AI%20and%20ML.jpg)

  [BLOGS](https://blog.e-zest.com)
  
  #### Elevating Product Engineering with AI and ML

  As technology evolves and customer choices broaden, there is an increasing ...

  [Read more](https://blog.e-zest.com/elevating-product-engineering-with-ai-and-ml)
- ![e-Zest – An Accion Labs Company gets Recognition as a Contender in the ISG Provider Lens™ Study on Digital Engineering Services 2024](https://blog.e-zest.com/hubfs/e-Zest%20%E2%80%93%20An%20Accion%20Labs%20Company%20-%20Gets%20Recognition%20as%20a%20Contender%20in%20the%20ISG%20Provider%20LensTM%20Study%20on%20Digital%20Engineering%20Services%202024.jpg)

  [NEWS](https://blog.e-zest.com/news)
  
  #### e-Zest – An Accion Labs Company gets Recognition as a Contender in the ISG Provider Lens™ Study on Digital Engineering Services 2024

  We are delighted to announce that e-Zest – An Accion Labs Company has been ...

  [Read more](https://blog.e-zest.com/news/e-zest-an-accion-labs-company-gets-recognition-as-a-contender-in-the-isg-provider-lens-study-on-digital-engineering-services-2024)
- ![e-Zest Solutions supports Digital Pune Mission](https://blog.e-zest.com/hubfs/blog-files/Digital%20Literacy%20Bus%20e-Zest.png)

  [CSR](https://blog.e-zest.com/csr)
  
  #### e-Zest Solutions supports Digital Pune Mission

  **Pune, India:** e-Zest Solutions, a leading digital technology innovation ...

  [Read more](https://blog.e-zest.com/csr/e-zest-solutions-supports-digital-pune-mission)

- [Work](https://www.e-zest.com/our-work)
- [Services](https://www.e-zest.com/our-services)
- [Insights](https://blog.e-zest.com)
- [Careers](https://www.e-zest.com/careers)
- [Enterprise Data](https://www.e-zest.com/enterprise-data-services)
- [Generative AI](https://www.e-zest.com/generative-ai)
- [Innovations](https://www.e-zest.com/innovations)
- [Healthcare](https://healthcare.e-zest.com)
- [About](https://www.e-zest.com/about-us)
- [Contact](https://www.e-zest.com/contact-us)

- [Blog](https://blog.e-zest.com/)
- [News](https://blog.e-zest.com/news)
- [CSR](https://blog.e-zest.com/csr)

- [![Linkedin Icon](https://blog.e-zest.com/hubfs/icons/linkedin_icon_white.svg)](https://www.linkedin.com/company/e-zest-solutions/)
- [![Twitter Icon](https://blog.e-zest.com/hubfs/twitter-logo-silhouette%20(5).svg)](https://twitter.com/ezest)
- [![Facebook Icon](https://blog.e-zest.com/hubfs/facebook-app-logo%20(4).svg)](https://www.facebook.com/61259256638)
- [![Instagram Icon](https://blog.e-zest.com/hubfs/instagram-logo%20(4).svg)](https://www.instagram.com/ezestsolutions/)
- [![Youtube Icon](https://blog.e-zest.com/hubfs/icons/youtube_icon_white.svg)](https://www.youtube.com/user/ezestcorporate)

[![Go to top icon](https://blog.e-zest.com/hubfs/AA%20Assets/top%20button.svg)](https://blog.e-zest.com/how-to-setup-docker-container-for-magento2#top)

Hit enter to search or ESC to close

Insights

e-Zest members share technology ideas to foster digital transformation.

- [Blog](https://blog.e-zest.com)
- [News](https://blog.e-zest.com/news)
- [Podcasts](https://www.e-zest.com/podcasts)
- [Healthcare](https://blog.e-zest.com/healthcare)
- [CSR](https://blog.e-zest.com/csr)
- [Whitepaper](https://blog.e-zest.com/whitepaper)
- [Playbook](https://blog.e-zest.com/playbook)
- [Media Kit](https://www.e-zest.com/media-kit)

# How to setup Docker Container for Magento 2

[Rajesh Rathod](https://blog.e-zest.com/author/rajesh-rathod)  Oct 15, 2021

[Docker](https://blog.e-zest.com/topic/docker) [Magento](https://blog.e-zest.com/topic/magento) [Ubuntu](https://blog.e-zest.com/topic/ubuntu) [Digital Commerce](https://blog.e-zest.com/topic/digital-commerce) [Magento 2.0](https://blog.e-zest.com/topic/magento-2-0)

- <https://www.linkedin.com/shareArticle?mini=true&url=https://blog.e-zest.com/how-to-setup-docker-container-for-magento2&title=&summary=&source=>
- <https://twitter.com/intent/tweet?source=https://blog.e-zest.com/how-to-setup-docker-container-for-magento2&text=How%20to%20setup%20Docker%20Container%20for%20Magento%202>
- <https://www.facebook.com/sharer/sharer.php?u=https://blog.e-zest.com/how-to-setup-docker-container-for-magento2>
- <https://www.instagram.com/ezestsolutions/?u=https://blog.e-zest.com/how-to-setup-docker-container-for-magento2>

Docker is an application that allows us to manage multiple applications in the simplest way in the docker container. Docker container is the bundle of all the resources required to run your application in an isolated process. The container is a simple virtual machine with all the necessary service/application setup for the application.

We can set up the entire technology stack for Magento in the container and create the image; The docker image is portable to create another container immediately as it is required for re-use

Prerequisites

- Ubuntu Server/Machine
- Account on docker hub if you want to create your own docker images and push it to Docker Hub for the public uses

Docker Installation

Step 1

1. Update your existing packages in ubuntu  
   **sudo apt-get update**
2. Install a few prerequisites package  
   **sudo apt install apt-transport-https ca-certificates curl software-properties-common**
3. Add GPG key to official Docker repository  
   **curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -**
4. Add Docker repository to APT sources  
   **sudo add-apt-repository "deb \[arch=amd64\] https://download.docker.com/linux/ubuntu bionic stable"**
5. Update newly added repo – **sudo apt-get update**
6. Install Docker  
   **sudo apt install docker-ce**
7. Check docker status, enable & disable  
   **sudo systemctl status docker**  
   **sudo systemctl enable docker**  
   **sudo systemctl disable docker**
8. Display other Docker commands  
   Use -   
   $ **docker**  
   $ **docker docker-subcommand –help**  
   $ **docker info**

Download/Pull official ubuntu Docker image

Command - docker pull ubuntu

![](https://blog.e-zest.com/hubfs/image-png-Oct-19-2021-06-43-35-39-AM.png)

To see available Docker images

Command – docker images

![](https://blog.e-zest.com/hubfs/image-png-Oct-19-2021-06-43-56-68-AM.png)

How to create a Docker container

docker container run -it -p 81:80 --name magento2 ubuntu bash

-it: It gives you interactive shell access into the Docker container

-p 81:80: port to execute the container

--name magento: Docker Name

ubuntu: docker image

bash: to get CLI interface for the docker

![](https://blog.e-zest.com/hubfs/image-png-Oct-19-2021-06-44-59-17-AM.png)

Check Available Docker

Command:

docker container ls  
docker container ls -a

![](https://blog.e-zest.com/hubfs/image-png-Oct-19-2021-06-45-28-68-AM.png)

To Commit your own customized Docker Images with all the resources

If you are working with Magento 2, you have to install a technology stack for the Magento 2 for ex- php, php-fpm, nginx, redis, varnish in the container. If you want to re-use this container by your own docker image, we can create/commit shareable docker images that can be re-used to Magento 2 direct project setup. Follow below commands

docker commit f9df6b49a43d image/ubuntu

f9df6b49a43d – Container Id

image/ubuntu - Docker image name

Mount/Map your Magento code directory to docker directory

You can map/mount your code directory (Source code interface) to Docker container directory for easy development; whatever changes have been done in your local directly will be synced immediately with the container directly.

For example: Your local machine directory path is - /var/www/html/m2-docker (Where you have cloned GIT LAB code) where you download Magneto source code

You can mount this project directory to Docker nginx/apache www directory for the development; follow the below command for directory mount

docker container run -it -p 81:80 --name magento2 -v /var/www/html/m2-docker:/var/www/html ubuntu bash

You can get a list of the active container using the below command

docker container ls  
docker container ls -a – It will give you all available container

Remove Docker container

We can remove/delete unused container using the below command

docker container rm 57e21b9d5ab7

rm – Remove

57e21b9d5ab7 – Container Id

![](https://blog.e-zest.com/hubfs/image-png-Oct-19-2021-06-50-46-78-AM.png)

Start/Stop Docker Container

docker container start magento2

docker container stop magento2

Log in to CLI access with a running container

docker container exec -it magento2 bash

If you want to leave the container running from the CLI, press CTRL+P+Q. With this command, you can exit from the container CLI, but your container will be running in the background.

*For More details, you can visit the links below*

[https://docs.docker.com/](https://docs.docker.com/)

[https://docs.docker.com/get-started/](https://docs.docker.com/get-started/)

[https://docs.docker.com/reference/](https://docs.docker.com/reference/)

[https://docs.docker.com/engine/reference/run/](https://docs.docker.com/engine/reference/run/)

[https://docs.docker.com/engine/reference/commandline/create/](https://docs.docker.com/engine/reference/commandline/create/)

- <https://twitter.com/intent/tweet?source=https://blog.e-zest.com/how-to-setup-docker-container-for-magento2&text=How%20to%20setup%20Docker%20Container%20for%20Magento%202>
- <https://www.facebook.com/sharer/sharer.php?u=https://blog.e-zest.com/how-to-setup-docker-container-for-magento2>
- <https://www.linkedin.com/shareArticle?mini=true&url=https://blog.e-zest.com/how-to-setup-docker-container-for-magento2&title=&summary=&source=>

### Similar Blog

[![Install Docker on AWS EC2 (Ubuntu 16.04)](https://blog.e-zest.com/hubfs/install-docker-on-aws-ec2.png) Install Docker on AWS EC2 (Ubuntu 16.04) Docker is a program that can implement a virtualization on your machine and you can pull any image of Operating System and launch ... By Amit Tidke Nov 14, 2018](https://blog.e-zest.com/install-docker-on-aws-ec2)

[![Docker Tutorial: Using it as a server Migration Tool](https://blog.e-zest.com/hs-fs/file-3395404509-png/blog-files/docker-tutorial.png) Docker Tutorial: Using it as a server Migration Tool **Public Cloud (e.g. AWS, Azure) \<-\> Private Cloud (e.g. Openstack) \<-\>physical servers** By Kunal Shah May 04, 2015](https://blog.e-zest.com/docker-tutorial-using-it-as-a-server-migration-tool/)

[![Integrating Magento with Marketo](https://blog.e-zest.com/hubfs/Integrating%20Magento%20with%20Marketo.png) Integrating Magento with Marketo **What is Marketo?** By Rajesh Rathod Jan 02, 2019](https://blog.e-zest.com/integrating-magento-with-marketo)

[![How to setup Google Tag Manager or Google Analytics in Magento 2?](https://blog.e-zest.com/hubfs/gtm-and-google-analytics-in-magento2.png) How to setup Google Tag Manager or Google Analytics in Magento 2? **What is GTM (Google Tag Manager)?** Google Tag Manager is a tag management system that allows you to quickly and easily update ... By Rajesh Rathod Sep 27, 2018](https://blog.e-zest.com/how-to-setup-google-tag-manager-or-google-analytics-in-magento-2)

[![Making Payment Method Visible Only For Admin in Magento 2](https://blog.e-zest.com/hubfs/blog-files/1.png) Making Payment Method Visible Only For Admin in Magento 2 Payment methods such as cash-on-delivery and check/money order need to visible in the admin-panel check-out section and not in ... By Rajesh Rathod Oct 11, 2017](https://blog.e-zest.com/making-payment-method-visible-only-for-admin-in-magento-2)

[![How to add custom image attribute for customer in Magento 2?](https://blog.e-zest.com/hubfs/magento-1.png) How to add custom image attribute for customer in Magento 2? Magento has a lot of core functionalities that we can we use for our project requirements. One of them has Magento 2 EE providing ... By Rajesh Rathod Sep 28, 2017](https://blog.e-zest.com/how-to-add-custom-image-attribute-for-customer-in-magento-2)

## Helping Organizations Thrive in the Digital Age

[Contact Us](https://www.e-zest.com/contact-us)

- [About](https://www.e-zest.com/about-us)
- [Services](https://www.e-zest.com/our-services)
- [Work](https://www.e-zest.com/our-work)
- [Insights](https://blog.e-zest.com/)
- [Healthcare](https://healthcare.e-zest.com/)
- [Accion Labs](https://www.accionlabs.com/)

- <https://www.linkedin.com/company/e-zest-solutions/>
- <https://twitter.com/ezest>
- <https://www.facebook.com/eZest/>
- <https://www.instagram.com/ezestsolutions/>
- <https://www.youtube.com/user/ezestcorporate>

- Dallas
- Detroit
- Hannover
- Vienna
- London
- Pune

 © 2025 e-Zest Solutions

- [Privacy Policy](https://www.e-zest.com/privacypolicy)
- [Cookie Policy](https://www.e-zest.com/cookie-policy)

 Contact us

 Contact us

e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.