Our blog

How to Setup Magento 2 with Docker

service-06
Setup Magento 2 with Docker

Easiest way to Setup Magento 2 with Docker

Prerequisites for: Setup Magento 2 with docker

• Install Development Tools
• Install Docker
• Install Docker Compose
• Magento 2 source code.

Setup Steps: For installing the Docker engine on Ubuntu

1.  sudo apt-get update
2.  sudo apt-get install \ 

 apt-transport-https \
 ca-certificates \
 curl \
 gnupg-agent \
 software-properties-common

Add Docker’s official GPG key:

 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
 sudo add-apt-repository \
“deb [arch=amd64] https://download.docker.com/linux/ubuntu \
(lsb_release -cs) \
stable”

INSTALL DOCKER-ENGINE

 sudo apt-get update
 sudo apt-get install docker-ce docker-ce-cli containerd.io

Verify that the Docker Engine is installed correctly by running the hello-world image.

sudo docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

Install Docker Compose:

Run this command to download the current stable release of Docker Compose:
sudo curl -L “https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)” -o /usr/local/bin/docker-compose
Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Test the installation.

docker-compose –version
docker-compose version 1.25.5, build 1110ad01

Download Magento 2

Setup Development Environment

1. Make a project directory on the desired location on your machine.
2. Extract the Docker zip Package shared with you in the project directory.
3. Now launch the development environment
docker-compose up -d –build
4. Let’s make sure that it’s up and running as planned. In a web browser, go to 127.0.0.1:8080

Install Magento 2

1. Extract the Magento 2 zip package in the Magneto folder created in the project directory.
2. Start Setting up Magento
3. Access your Docker web container’s command line.
docker exec -it webserver bash
4. Navigate to the web document root.
cd /var/www/html/
5. Install Magento 2 Before copying and pasting the command shown below into the Docker terminal, you must replace the values on lines 2-6 with your own details. On lines 7-8, replace the placeholder domain with the domain name you created earlier.

 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=db \
 –db-name=magento \
 –db-user= magento \
 –db-password= magento \
 –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

6. In your web browser, visit your website at https://localhost/

Now your Setup Magento 2 with Docker is completed

Helpful Docker Information & Commands

Docker Info

• Your database is persistent due to a data volume contained in the docker-compose.yml file. This means that when you tear down the virtual machine and spin it back up at a later date or time, your database will still be intact and ready to go.
• If you would like to use Sequel Pro or some other tool to connect to the database, it is accessible at 127.0.0.1:3306. The username is root and the password is root. The name of the database is magento.
• The VM includes phpMyAdmin for your convenience. It can be accessed from a web browser at 127.0.0.1:8080.

Docker Commands

• Spin Up
 docker-compose up -d –build
• Tear Down
 docker-compose down
• Connect to web container CLI
docker exec -it webserver bash
• Connect to database container CLI
 docker exec -it db bash
• Connect to redis container CLI
 docker exec -it db bash
• Connect to elasticsearch container CLI
docker exec -it elasticsearch bash

Docker Environment predefined values.

DocumentRoot: /var/www/html
PHP Version. Php7.2
Web Server: Nginx | Port: 80
Database: Mysql 5.7 | Port: 3306
Logins.
Username: root
Password: root
User for magento:
Username: magento
Password: magento
Database Name: magento
Redis: 6.0.3 | Port: 6379
Elasticsearch: 6.7.1 | Port: 9200, 9300
PHPmyadmin: 8080

© [2025] [Setup Magento 2 with Docker]. All rights reserved. | Powered by Techmaster Solutions | Privacy Policy | Terms of Service | Contact Us

Stay connected: [Social Media Links]

Subscribe for updates and insights.

Check out:  How to Setup Autodevops On Gitlab.

Leave a reply if you are facing any issues for Setup Magento 2 with docker or for any other queries

Disclaimer: Opinions expressed are solely those of the author and not professional advice.

Leave a Reply

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

Our blog

Our tips and solutions in technology services

How to setup Autodevops on gitlab

Gitlab AutoDevOps Gitlab AutodevOps is a pre-configured CI/CD pipeline and eliminates the complexities of software delivery without manually creating CI/CD pipeline. Background On Known Challenges:

Read More »

Free consultation

Contact us for a free IT consultation

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Tips for a perfect contact

01

Active listening, followed by clarifying questions, ensures a complete understanding.

02

Please provide clear and concise instructions or assistance to resolve the issue as efficiently as possible.

03

Continuously follow up to ensure that the issue is fully resolved and promptly offer any further assistance.