sohelrana09 / docker-magento

Mark Shust's Docker Configuration for Magento

Home Page:https://markshust.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

markoshust/docker-magento

Mark Shust's Docker Configuration for Magento

Supported Magento Versions Docker Hub Pulls - Nginx Docker Hub Pulls - PHP Maintained - Yes

Table of contents

Docker Hub

View Dockerfiles:

Usage

This configuration is intended to be used as a Docker-based development environment for Magento 2.

Folders:

  • images: Docker images for nginx and php
  • compose: sample setups with Docker Compose

The Magento 1 version of this development environment has been deprecated and is no longer supported. PHP 5 was used as it's base, and that version has reached end-of-life. If you still wish to use this setup, please reference compose/magento-1 on tag 20.1.1, but please be aware these images are no longer maintained.

Prerequisites

This setup assumes you are running Docker on a computer with at least 4GB of allocated RAM, a dual-core, and an SSD hard drive. Download & Install Docker Community Edition.

This configuration has been tested on Mac & Linux.

Windows Configurations: The Windows configuration does not currently work and is in need of a contributor to get functional once again. Please see issue 100 to contribute.

Quick Setup

Automated Setup (New Project)

macOS & Linux Only

Run this automated one-liner from the directory you want to install your project to:

curl -s https://raw.githubusercontent.com/markoshust/docker-magento/master/lib/onelinesetup|bash -s -- magento2.test 2.3.0

The magento2.test above defines the hostname to use, and the 2.3.0 defines the Magento version to install. Note that since we need a write to /etc/hosts for DNS resolution, you will be prompted for your system password during setup.

After the one-liner above completes running, you should be able to access your site at https://magento2.test.

Manual Setup

Same result as the one-liner above. Just replace magento2.test references with the hostname that you wish to use.

# Quick setup for a new instance of Magento 2:
curl -s https://raw.githubusercontent.com/markoshust/docker-magento/master/lib/template|bash -s -- magento-2

# New projects can easily download by version:
bin/download 2.3.0

# or if you'd rather install with Composer, run:
#
# OPEN SOURCE:
#
# rm -rf src
# composer create-project --repository=https://repo.magento.com/ --ignore-platform-reqs magento/project-community-edition=2.3.0 src
#
# COMMERCE:
#
# rm -rf src
# composer create-project --repository=https://repo.magento.com/ --ignore-platform-reqs magento/project-enterprise-edition=2.3.0 src

# Existing projects, instead of running the above replace the contents of /src with the source code of your existing Magento instance

echo "127.0.0.1 magento2.test" | sudo tee -a /etc/hosts

# For new setups:
bin/setup magento2.test

# For existing installations:
# bin/start
# bin/composer install

open https://magento2.test

For more details on how everything works, see the extended setup readme.

Custom CLI Commands

  • bin/bash: Drop into the bash prompt of your Docker container. The phpfpm container should be mainly used to access the filesystem within Docker.
  • bin/dev-urn-catalog-generate: Generate URN's for PHPStorm and remap paths to local host. Restart PHPStorm after running this command.
  • bin/cli: Run any CLI command without going into the bash prompt. Ex. bin/cli ls
  • bin/clinotty: Run any CLI command with no TTY. Ex. bin/clinotty chmod u+x bin/magento
  • bin/composer: Run the composer binary. Ex. bin/composer install
  • bin/copyfromcontainer: Copy folders or files from container to host. Ex. bin/copyfromcontainer vendor
  • bin/copytocontainer: Copy folders or files from host to container. Ex. bin/copytocontainer --all
  • bin/download: Download & extract specific Magento version to the src directory. Ex. bin/download 2.3.0
  • bin/fixowns: This will fix filesystem ownerships within the container.
  • bin/fixperms: This will fix filesystem permissions within the container.
  • bin/grunt: Run the grunt binary. Note that this runs the version from the node_modules directory for project version parity. Ex. bin/grunt exec
  • bin/magento: Run the Magento CLI. Ex: bin/magento cache:flush
  • bin/node: Run the node binary. Ex. bin/node --version
  • bin/npm: Run the npm binary. Ex. bin/npm install
  • bin/remove: Remove all containers.
  • bin/removevolumes: Remove all volumes.
  • bin/restart: Stop and then start all containers.
  • bin/root: Run any CLI command as root without going into the bash prompt. Ex bin/root apt-get install nano
  • bin/rootnotty: Run any CLI command as root with no TTY. Ex bin/rootnotty chown -R app:app /var/www/html
  • bin/setup: Run the Magento setup process to install Magento from the source code, with optional domain name. Defaults to magento2.test. Ex. bin/setup magento2.test
  • bin/start: Start all containers, good practice to use this instead of docker-compose up -d, as it may contain additional helpers.
  • bin/stop: Stop all containers.
  • bin/xdebug: Disable or enable Xdebug. Accepts params disable (default) or enable. Ex. bin/xdebug enable

Misc Info

Database

The hostname of each service is the name of the service within the docker-compose.yml file. So for example, MySQL's hostname is db (not localhost) when accessing it from within a Docker container. Elasticsearch's hostname is elasticsearch.

Composer Authentication

First setup Magento Marketplace authentication (details in the DevDocs).

After doing so, copy the auth sample file to:

  • cp src/auth.json.sample src/auth.json

Then update the username and password values with your Magento public and private keys, respectively.

Xdebug & VS Code

Install and enable the PHP Debug extension from the Visual Studio Marketplace.

Otherwise, this project now automatically sets up Xdebug support with VS Code. If you wish to set this up manually, please see the .vscode/launch.json file.

Xdebug & PHPStorm

  1. First, install the Chrome Xdebug helper. After installed, right click on the Chrome icon for it and go to Options. Under IDE Key, select PHPStorm from the list and click Save.

  2. Next, enable Xdebug in the PHP-FPM container by running: bin/xdebug enable, the restart the docker containers (CTRL+C then bin/start).

  3. Then, open PHPStorm > Preferences > Languages & Frameworks > PHP and configure:

    • CLI Interpreter

      • Create a new interpreter and specify From Docker, and name it markoshust/magento-php:7-2-fpm.
      • Choose Docker, then select the markoshust/magento-php:7-2-fpm image name, and set the PHP Executable to php.
    • Path mappings

      • Don't do anything here as the next Docker container step will automatically setup a path mapping from /var/www/html to ./src.
    • Docker container

      • Remove any pre-existing volume bindings.
      • Ensure a volume binding has been setup for Container path of /var/www/html mapped to the Host path of ./src.
  4. Open PHPStorm > Preferences > Languages & Frameworks > PHP > Debug and set Debug Port to 9001.

  5. Open PHPStorm > Preferences > Languages & Frameworks > PHP > DBGp Proxy and set Port to 9001.

  6. Open PHPStorm > Preferences > Languages & Frameworks > PHP > Servers and create a new server:

    • Set Name and Host to your domain name (ex. magento2.test)
    • Set Port to 8000
    • Check the Path Mappings box and map src to the absolute path of /var/www/html
  7. Go to Run > Edit Configurations and create a new PHP Remote Debug configuration by clicking the plus sign and selecting it. Set the Name to your domain (ex. magento2.test). Check the Filter debug connection by IDE key checkbox, select the server you just setup, and under IDE Key enter PHPSTORM. This IDE Key should match the IDE Key set by the Chrome Xdebug Helper. Then click OK to finish setting up the remote debugger in PHPStorm.

  8. Open up src/pub/index.php, and set a breakpoint near the end of the file. Go to Run > Debug 'magento2.test', and open up a web browser. Ensure the Chrome Xdebug helper is enabled by clicking on it > Debug. Navigate to your Magento store URL, and Xdebug within PHPStorm should now trigger the debugger and pause at the toggled breakpoint.

License

MIT

About

Mark Shust's Docker Configuration for Magento

https://markshust.com

License:MIT License


Languages

Language:Shell 41.2%Language:Dockerfile 32.3%Language:PowerShell 26.5%