Mark Shust's Docker Configuration for Magento
View Dockerfiles:
This configuration is intended to be used as a Docker-based development environment for both Magento 1 and Magento 2.
Folders:
images
: Docker images for nginx and phpcompose
: sample setups with Docker Compose
Nginx assumes you are running Magento 2, however you can easily run it with Magento 1 using the provided configuration file. Here is an example of this setup with Docker Compose.
The PHP images are fairly agnostic to which version of Magento you are running. The PHP 5 images do assume you are running Magento 1, and the PHP 7 images do assume you are running Magento 2, however the main difference is cronjob setup, and they can be easily modified for inverse usage.
This setup assumes you are running Docker on a computer with at least 16GB RAM, a quad-core, and an SSD hard drive. Download & Install Docker Community Edition.
This configuration has been tested on Mac, but should also work on Mac, Windows and Linux.
If you are using a Mac, it is strongly recommended for you to apply these performance tuning changes to Docker for Mac before starting.
- Setup a new project using the Magento 2 compose skeleton:
mkdir magento2 && cd $_
git init
git remote add origin [email protected]:markoshust/docker-magento.git
git fetch origin
git checkout origin/master -- compose/magento-2
mv compose/magento-2/* .
rm -rf compose .git
git init
-
Download the Magento source code to the
src
folder with:./bin/download 2.2.2
-
Setup your ip loopback for proper IP resolution with Docker:
./bin/initloopback
-
Add an entry to
/etc/hosts
with your custom domain:10.254.254.254 magento2.test
(assuming the domain you want to setup ismagento2.test
). Be sure to use a.test
tld, as.localhost
and.dev
will present issues with domain resolution. -
Start your Docker containers with:
./bin/start
. -
Run Magento's setup install process with the command:
./bin/setup
. Feel free to edit this file to your liking; at the very least you will probably need to update thebase-url
value to the domain you setup in step 6. -
You may now access your site at
http://magento2.test
(or whatever domain you setup).
See the compose
folder for sample setups for both Magento 1 and Magento 2. Basically your source code should go in the src
folder, and you can then kick your project off with ./bin/start
. You may have to complete a few of the steps above to get things functioning properly.
./bin/bash
: Drop into the bash prompt of your Docker container. Thephpfpm
container should be mainly used to access the filesystem within Docker../bin/cli
: Run any CLI command without going into the bash prompt. Ex../bin/cli ls
./bin/composer
: Run the composer binary. Ex../bin/composer install
./bin/download
: Download a version of Magento to thesrc
directory. Ex../bin/download 2.2.2
./bin/fixperms
: This will fix filesystem ownerships and permissions within Docker../bin/initloopback
: Setup your ip loopback for proper Docker ip resolution../bin/magento
: Run the Magento CLI. Ex:./bin/magento cache:flush
./bin/setup
: Run the Magento setup process to install Magento from the source code../bin/start
: Start the Docker Compose process and your app. Ctrl+C to stop the process../bin/xdebug
: Disable or enable Xdebug. Ex../bin/xdebug enable
- The hostname of each service is the name of the service within the
docker-compose.yml
file. So for example, MySQL's hostname isdb
(notlocalhost
) when accessing it from a Docker container.
Open PHPStorm > Preferences > Languages & Frameworks > PHP
and configure:
-
CLI Interpreter
:- Create a new interpreter and specify
From Docker
, and name itphpfpm
. - Choose
Docker
, then select themarkoshust/magento-php:7-0-fpm
image name, and set thePHP Executable
tophp
. - Under
Additional > Debugger Extension
, enter/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
. - Hitting the reload executable button should find the correct PHP Version and Xdebug debugger configuration.
- Create a new interpreter and specify
-
Path mappings
:- Ensure local path is set to
./src
and is set to the remote path of/var/www/html
.
- Ensure local path is set to
-
Docker container
:- Ensure a volume binding has been setup for Container path of
/var/www/html
mapped to the Host path of~/src
.
- Ensure a volume binding has been setup for Container path of
Open PHPStorm > Preferences > Languages & Frameworks > PHP > Debug
and set Debug Port to 9001
.
Open PHPStorm > Preferences > Languages & Frameworks > PHP > DBGp Proxy
and set:
- IDE key:
PHPSTORM
- Host:
10.254.254.254
- Port:
9001
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
Create a new server at PHPStorm > Preferences > Languages & Frameworks > PHP > Servers
. Set your domain (ex. magento2.test
) as the name and host, check Shared
, leave port 80
, and debugger Xdebug
. Check Use path mappings
and assigned the src
File/Directory to the absolute path on the server of /var/www/html
.
Create a new PHP Remote Debug
configuration at Run > Edit Configurations
. Set the Name to your domain (ex. magento2.test
). Check Filter debug connection by IDE Key
, select the server of your domain name (ex. magento2.test
), and set IDE key to PHPSTORM
. The Validate
functionality will most likely not work with the Docker container, but doesn't affect the ability to use Xdebug.
Open up src/pub/index.php
, and set a breakpoint near the end of the file. Go to Run > Debug localhost
, and open up a web browser. Be sure to install a plugin like Xdebug helper which sets the IDE key to PHPStorm
automatically for you. Enable the browser extension and activate it on the site, and reload the site. Xdebug within PHPStorm should now enable the debugger and stop at the toggled breakpoint.
Please first setup Magento Marketplace authentication (details in the DevDocs).
Place your auth token at ~/.composer/auth.json
with the following contents, like so:
{
"http-basic": {
"repo.magento.com": {
"username": "MAGENTO_PUBLIC_KEY",
"password": "MAGENTO_PRIVATE_KEY"
}
}
}