Skip to content

Dockerized Magento example. Running Magento in a stack includes Nginx/PHP-FPM web server, Mysql, Redis, Varnish.

Notifications You must be signed in to change notification settings

hanhpv/dockerized-magento

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dockerized-magento

Dockerized Magento example. Running Magento in a stack includes Nginx/PHP-FPM web server, Mysql, Redis, Varnish.

Mysql Database

For database, we use mysql offical image. You can change the root password through environment variable MYSQL_ROOT_PASSWORD. To keep the data persitence, we create a volume and mount it to a directory under var: ./var/lib/mysql:/var/lib/mysql

Load a mysql dump file to the container

To import the .sql file to a database in the container, run this command in terminal:

docker exec -i <mysql_container_name> mysql -uroot -p<mysql_root_password> <datbase name> < dump.sql

Ex:

docker exec -i test_db_1 mysql -uroot -proot test < dump.sql

Varnish Caching

The docker-compose.yml include a Varnish service. The default.vcl file is generated by Turpentine - Varnish Cache extension for Magento and must be put in var directory. The current Varnish version is 4.0. If you don't want Varnish cache, just remove it from docker-compose.yml

Debugging with PHPSTORM

  1. Find your host machine IP by running ifconfig (Mac, Linux) or ipconfig on Windows and add the value to XDEBUG_REMOTE_HOST environment variable in docker-compose.yml
  2. Create a file named server.location in Magento root/var/nginx/ and put in that the line server_name your_virtual_host_url; Ex: server_name test.local;
  3. Xdebug is configured to listen on port 9009, not the default 9000 (to avoid conflict with PHP-FPM). In PHPSTORM > Prefences > Languages & Frameworks > PHP > Debug, change the Debug port to 9009
  4. Also in PHP section > Servers, add a new server with name and host are same as the one in step 2. Check the option User path mappings and edit the Absolute path on server to /var/www/html
  5. Install the Xdebug bookmarlets so we can start and stop the debugging from browser. Link here https://www.jetbrains.com/phpstorm/marklets/

Happy debugging!

docker-compose wrapper

This is a script to shorten the docker-compose commands. It helps us much easier working with the containers. The script was copied from https://github.com/andreaskoch/dockerized-magento/blob/master/magento and customized to work with my stack.

To use it, run this command in the terminal: chmod +x magento && cp magento /usr/local/bin/dcw. Then we will have a command called dcw. It must be run from within the Magento root directory.

Available commands:

start      Starts the docker containers (and triggers the
             installation if magento is not yet installed)
stop       Stops all docker containers
restart    Restarts all docker containers
status     Prints the status of all docker containers
stats      Displays live resource usage statistics of all containers
magerun    Executes magerun in the magento root directory
composer   Executes composer in the magento root directory
enter      Enters the bash of a given container type (e.g. php, mysql)
destroy    Stops all containers and removes all data

About

Dockerized Magento example. Running Magento in a stack includes Nginx/PHP-FPM web server, Mysql, Redis, Varnish.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published