Complete Magneto 2 Install in docker
Magento 2.4.6 Docker Environment
Prerequirsite = 8gb preffered(6 gb ram)
Services : Nginx 1.22, PHP 8.2-fpm-buster, Mariadb 10.6
Tree
git clone https://github.com/puneetk00/mg246-docker.git
├── CHANGELOG.md
├── README.md
├── docker
│ ├── nginx
│ │ ├── Dockerfile
│ │ ├── default.conf
│ │ └── m2-config
│ │ └── nginx.conf
│ └── php
│ ├── Dockerfile
│ └── www.conf
├── docker-compose.dev.yml
├── docker-compose.yml
└── magento246
Reference Github = https://github.com/puneetk00/mg246-docker and yt video = https://www.youtube.com/watch?v=Qe6MaKT4y4s
Magento 2.4.6-p2 Docker Setup:
Download and install docker app (windows/Mac)
Docker > Preferences > Resources > Advanced : at least 4 or 5 CPUs and 16.0 GB RAM
Local machine have alteast 32GB RAM(Recommended)
Clone mg246-docker repository and Build the docker Images:
* Goto "magento2-docker" folder and create:- mkdir magneto246 && mkdir db-data * docker-compose build * docker-compose up -d
Add System variable in environmental settings
SHELL=/bin/bash
(windows)To show Running Containers use command
docker ps
docker ps
9edaa3a3fd13 nginx:1.22 "nginx -g 'daemon of…" 12 minutes ago Up About a minute 0.0.0.0:80->80/tcp, :::80->80/tcp nginx
8e5ce3425639 mailhog/mailhog:latest "MailHog" 12 minutes ago Up 12 minutes 0.0.0.0:1025->1025/tcp, :::1025->1025/tcp, 0.0.0.0:8025->8025/tcp, :::8025->8025/tcp mail
24173dd2faf6 magento2-docker_php "docker-php-entrypoi…" 12 minutes ago Up 12 minutes 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp php
9552f52c3ce8 redis:latest "docker-entrypoint.s…" 12 minutes ago Up 12 minutes 6379/tcp redis
42756510ba9b mariadb:10.6 "docker-entrypoint.s…" 12 minutes ago Up 12 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp mariadb
ee97a9094860 rabbitmq:3-management "docker-entrypoint.s…" 12 minutes ago Up 12 minutes 4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, :::5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, :::15672->15672/tcp rabbitmq
6944566615b7 elasticsearch:7.17.12 "/usr/local/bin/dock…" 12 minutes ago Up 12 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch
7dab612ad6ec redislabs/redisinsight:latest "bash ./docker-entry…" 12 minutes ago Up 12 minutes 0.0.0.0:8001->8001/tcp, :::8001->8001/tcp redisinsight
- Install magento Instance:
Connect to php container:
* docker exec -it php bash
* cd /var/www/magento246
* If its an existent project, clone project repository to the 'magento246', then update env.php and go to #8
* Install Magento Instance in magento246 ( https://devdocs.magento.com/guides/v2.4/install-gde/composer.html )
Add your key before create your project. Some time public key and private key not aksing and througing message "you haven't provide your magento authentication keys"
composer config -g http-basic.repo.magento.com $MAGENTO_PUBLIC_KEY $MAGENTO_PRIVATE_KEY
Example
composer config -g http-basic.repo.magento.com 0ff912c89b6b970e417526cf75077be2 c70c62bbd23387504ca76a0e20be5091
1. composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.6 .
* enter your Magento authentication keys
2. Install M2 via CLI(/var/www/magento246):
php bin/magento setup:install \
--base-url=http://magento246.loc/ \ #yha public ip dalo/localhost
--db-host=mariadb \
--db-name=magento246 \
--db-user=root \
--db-password=root \
--admin-firstname=admin \
--admin-lastname=admin \
--admin-email=admin@admin.com \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1 \
--search-engine=elasticsearch7 \
--elasticsearch-host=elasticsearch \
--elasticsearch-index-prefix=magento246 \
--elasticsearch-port=9200
3. Cross check if ES is configured, if not update the below setting in app/etc/env.php: mostly nhi hoti hai to add kroo
'system' => [
'default' => [
'catalog' => [
'search' => [
'engine' => 'elasticsearch7',
'elasticsearch7_server_hostname' => 'elasticsearch',
'elasticsearch7_server_port' => '9200',
'elasticsearch7_index_prefix' => 'magento246'
]
]
]
],
4. Enable Developer Mode: php bin/magento deploy:mode:set developer (Choice hai kr bhi skte ho nhi bhi)
5. Make sure cache enabled : php bin/magento cache:enable
6. Configure Redis default/page caching
php bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=redis --cache-backend-redis-port=6379 --cache-backend-redis-db=0
bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=redis --page-cache-redis-db=1
7. Configure Redis for session storage
php bin/magento setup:config:set --session-save=redis --session-save-redis-host=redis --session-save-redis-port=6379 --session-save-redis-log-level=4 --session-save-redis-db=2
8. Run the cli commands:
* php bin/magento setup:upgrade
* php bin/magento setup:di:compile
* php -dmemory_limit=6G bin/magento setup:static-content:deploy -f
* chmod -R 777 var pub generated app/etc/*
#Inside php docker container = /etc/magneto246/ php bin/magneto module:status | grep -i "auth" php bin/magneto module:dis magneto -two factor and other bdi wali php bin/magneto s:upgrade php bin/magneto s:d:c php bin/magneto s:s:d -f chmod -R 777 var pub generated app/etc/*
Configure your hosts file: 127.0.0.1 magento246.loc
In windows:- c:\Windows\System32\Drivers\etc\hosts.
Mac/Ubuntu:- /etc/hosts
Open http://magento246.loc/ Or Open http://localhost
-
Admin panel path in php container =cat /var/www/magento246/app/etc/env.php
Admin id = admin password = admin123
MailHog:- You are able to see all the emails from docker(Magento Instance) on http://localhost:8025/
Eg: php -r "$from = $to = 'youremail@gmail.com'; $x = mail($to, 'subject'.time(), 'Hello World', 'From: '. $from); var_dump($x);" o/p - bool(true)
Note: While installing the Mailhog, if we get the below error:
"ERROR: Get https://registry-1.docker.io/v2/mailhog/mailhog/manifests/latest: unauthorized: incorrect username or password"
Try first:
$ docker logout
and then pull again. As it is public repo you shouldn't need to login
Subscribe to my newsletter
Read articles from Sarthak Tyagi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by