Docker for Magento 2
==================================
A project running Magento 2 in Docker.
Demo host name: http://mage.demo/
Dependencies:
Please disable apache or nginx if they run in port 80, because project use port 80 for webserver.
Add network for docker in you computer:
make networks
Once you’re done init project,
cd
to your project/etc/hosts
“127.0.0.1 mage.demo”make init
.make mage_install
.make grunt_init
.You can access your application via mage.demo
, if you’re running the containers directly,
Service | Address outside containers |
---|---|
Webserver | mage.demo |
MySQL | host: localhost ; port: 8082 |
PHPMyAdmin | localhost:8181 |
In case you want to use new domain in virtual host /etc/hosts
/etc/hosts
nginx/conf.d/mage2.conf
`docker-compose exec app mage config:set --scope=default web/unsecure/base_url http://example.com/`
`docker-compose exec app mage config:set --scope=default web/secure/base_url http://example.com/`
make rm_fullcache && make rm_session
make restart
You’ll need to configure your application to use any services you enabled:
Service | Hostname | Port number |
---|---|---|
php-fpm | php-fpm | 9000:9000 |
MySQL | mysql | 8082:3306 (default) |
PHPMyAdmin | phpmyadmin | 8181:80 |
Nginx | webserver | 80:80 |
Grunt|grunt|
Note: you need to cd first to where your docker-compose.yml file lives.
docker-compose up -d
docker-compose up
. You will see a stream of logs for every container running.docker-compose stop
docker-compose kill
docker-compose logs
docker-compose exec SERVICE_NAME COMMAND
where COMMAND
is whatever you want to run.
* Shell into the PHP container, `docker-compose exec php-fpm bash` \
* Run symfony console, `docker-compose exec php-fpm bin/console` \
* Open a mysql shell, `docker-compose exec mysql mysql -uroot -pCHOSEN_ROOT_PASSWORD` \
docker-compose exec app composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition .
docker-compose exec app composer install
We need init grunt for project, in app\src
you need 2 file package.json, Gruntfile.js \
Run command to init grunt : make grunt_init
\
Some command for grunt:
docker-compose run --rm grunt {command}
docker-compose run --rm grunt grunt -V
docker-compose run --rm grunt grunt npm install
docker-compose run --rm grunt grunt npm update
docker-compose run --rm grunt grunt grunt clean:{theme}
docker-compose run --rm grunt grunt grunt clean:blank
docker-compose run --rm grunt grunt grunt exec:{theme}
docker-compose run --rm grunt grunt grunt exec:blank
docker-compose run --rm grunt grunt grunt less:{theme}
docker-compose run --rm grunt grunt grunt less:blank
docker-compose run --rm grunt grunt grunt watch
CLI help running command of project
docker-compose run -rm cli mage
docker-compose run -rm cli mage sys:check
Makefile help we summarize some common commands, please view Makefile for clean more.
We have a lot of aliases to run command for docker compose
make add_aliases
- Php cron
- Redis Cache
- Elastic Search
- Muliple Stores