|
1 | | -# Magento 2 Docker project |
| 1 | +# Magento 2 Docker for Developer project |
| 2 | + |
| 3 | +Using this docker project you can initiate a new project or import the existent one. |
| 4 | + |
| 5 | +## Preparation |
| 6 | +1. Open https://www.docker.com/ |
| 7 | +1. Register new account or login with an existent one |
| 8 | +1. Download and install docker app |
| 9 | + |
| 10 | + |
| 11 | +## Install a vanilla Magento |
| 12 | +1. Import "magento2-docker" repository |
| 13 | +2. Open "magento2-docker" folder in terminal app |
| 14 | +3. Create "magento" folder: |
| 15 | +`mkdir magento` |
| 16 | +4. Build and run all docker components: |
| 17 | +`docker-compose up --build` |
| 18 | +5. After configuration is build and running open a new terminal tab and connect to php container: |
| 19 | +`docker exec -it php bash` |
| 20 | +6. Open "magento" folder and verify that the folder is empty: |
| 21 | +`cd /var/www/magento; ls -la` |
| 22 | +7. Choose your approach below and install the project |
| 23 | + |
| 24 | +7.1 If you want to install a vanilla Magento instance you need to go to https://devdocs.magento.com/guides/v2.3/install-gde/composer.html |
| 25 | +and create a new project to the current directory. |
| 26 | + |
| 27 | +Example: |
| 28 | +`composer create-project --repository=https://repo.magento.com/ magento/project-enterprise-edition .` |
| 29 | + |
| 30 | +7.2 If you want to install an existent project you need to clone project repository to the "magento" folder: |
| 31 | +`git clone <--project_repository_url--> .` |
| 32 | + |
| 33 | +When prompted, enter your Magento authentication keys. |
| 34 | + |
| 35 | +8\. Once composer install is done run Magento install command: |
| 36 | +``` |
| 37 | +php bin/magento setup:install \ |
| 38 | + --db-host=db \ |
| 39 | + --db-name=magento \ |
| 40 | + --db-user=magento \ |
| 41 | + --db-password=123123q \ |
| 42 | + --base-url=http://magento.local \ |
| 43 | + --backend-frontname=admin \ |
| 44 | + --admin-user=admin \ |
| 45 | + --admin-password=123123q \ |
| 46 | + --admin-email=admin@test.com \ |
| 47 | + --admin-firstname=Magento \ |
| 48 | + --admin-lastname=User \ |
| 49 | + --language=en_US \ |
| 50 | + --currency=USD \ |
| 51 | + --timezone=America/Chicago \ |
| 52 | + --skip-db-validation \ |
| 53 | + && chown -R www-data:www-data . |
| 54 | +``` |
| 55 | + |
| 56 | +9\. Update your laptop hosts file: `127.0.0.1 magento.local` |
| 57 | + |
| 58 | +10\. Open http://magento.local/ |
| 59 | + |
| 60 | +## Connect to containers via SSH |
| 61 | +Docker configuration contains such components as: |
| 62 | +- web (nginx service) |
| 63 | +- php (php-fpm service) |
| 64 | +- db (MySQL service) |
| 65 | +- redis (redis service) |
| 66 | +- mail (mailhog mail service) |
| 67 | + |
| 68 | +For connecting to container via SSH you need use the command: |
| 69 | +`docker exec -it <--container_name--> bash`, where <--container_name--> is container name |
| 70 | + |
| 71 | +Example: |
| 72 | +`docker exec -it web` |
| 73 | + |
| 74 | +## Reloading services |
| 75 | + |
| 76 | +### Reload ngnix |
| 77 | +``` |
| 78 | +docker exec -it web |
| 79 | +/etc/init.d/nginx reload |
| 80 | +``` |
| 81 | + |
| 82 | +### Reload php |
| 83 | +``` |
| 84 | +docker docker-compose restart php |
| 85 | +``` |
| 86 | + |
| 87 | +## Connect to MySQL from your laptop |
| 88 | +You're able to connect to MySQL using "0.0.0.0" as host, port should be default one - "3306", credentials from .env file |
| 89 | + |
| 90 | +## Using MailHog for sending emails |
| 91 | +You're able to find all the email you send from Magento instance on http://localhost:8025/ |
| 92 | + |
| 93 | +## Switch to PHP 7.x |
| 94 | +1\. Shutdown your current docker instance |
| 95 | + |
| 96 | +2\. Change PHP version in ./php/Docker file to needed version |
| 97 | + |
| 98 | +Example: |
| 99 | + |
| 100 | +If you need to change PHP version from 7.2 to 7.1 you need to change `FROM php:7.2-fpm` to `FROM php:7.1-fpm` |
| 101 | + |
| 102 | +3\. Build and run all docker components: |
| 103 | +`docker-compose up --build` |
0 commit comments