Tree Stones Docker Configuration for Shopware
This is a highly performing setup for developers. It also includes a bunch of helper tools like create and config local ssl, short access to container, fix ownership and permissions or easily enable / disable xdebug. It's inspired by Docker Magento Setup of Mark Shust.
It is so fast because it only shares the really needed files to work on during development between Docker container and local host. All the huge amount on files in vendor or var/cache folder aren't synced.
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 Desktop.
This configuration has been tested on Mac & Linux. Windows is supported through the use of Docker on WSL.
TBD
TBD
TBD
TBD
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/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/dev-urn-catalog-generate
: Generate URN's for PHPStorm and remap paths to local host. Restart PHPStorm after running this command.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. Ex.bin/grunt exec
bin/magento
: Run the Magento CLI. Ex:bin/magento cache:flush
bin/mysql
: Run the MySQL CLI with database config from env/db.env. Exbin/mysql -e "EXPLAIN acl_resource"
bin/node
: Run the node binary. Ex.bin/node --version
bin/npm
: Run the npm binary. Ex.bin/npm install
bin/pwa-studio
: (BETA) Start the PWA Studio server. Note that Chrome will throw SSL cert errors and not allow you to view the site, but Firefox will.bin/redis
: Run a command from the redis container. Ex.bin/redis redis-cli monitor
bin/remove
: Remove all containers.bin/removeall
: Remove all containers, networks, volumes, and images.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. Exbin/root apt-get install nano
bin/rootnotty
: Run any CLI command as root with no TTY. Exbin/rootnotty chown -R app:app /var/www/html
bin/setup
: DOES NOT WORK ATM. Run the Shopware setup process to install Shopware from the source code, with optional domain name. Defaults toshopware.test
. Ex.bin/setup shopware.test
bin/setup-ssl
: Generate an SSL certificate for one or more domains. Ex.bin/setup-ssl shopware.test shopware.test
bin/setup-ssl-ca
: Generate a certificate authority and copy it to the host.bin/start
: Start all containers, good practice to use this instead ofdocker-compose up -d
, as it may contain additional helpers.bin/status
: Check the container status.bin/stop
: Stop all containers.bin/xdebug
: Disable or enable Xdebug. Accepts paramsdisable
(default) orenable
. 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 is db
(not localhost
) when accessing it from within a Docker container. Elasticsearch's hostname is elasticsearch
.
Here's an example of how to connect to the MySQL cli tool of the Docker instance:
bin/cli mysql -h db -ushopware -pshopware shopware
You can use the bin/clinotty
helper script to import a database. This example uses the root MySQL user, and looks for the dbdump.sql
file in your local host directory:
bin/clinotty mysql -h db -u root -pshopware shopware < dbdump.sql
View emails sent locally through Mailhog by visiting http://{yourdomain}:8025
-
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.
-
Next, enable Xdebug in the PHP-FPM container by running:
bin/xdebug enable
, the restart the docker containers (CTRL+C thenbin/start
). -
Then, open
PHPStorm > Preferences > Languages & Frameworks > PHP
and configure:-
CLI Interpreter
- Create a new interpreter and specify
From Docker
, and name itshopware-php
. - Choose
Docker
, then select theshopware-php
image name, and set thePHP Executable
tophp
.
- Create a new interpreter and specify
-
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
.
- Don't do anything here as the next
-
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
.
-
-
Open
PHPStorm > Preferences > Languages & Frameworks > PHP > Debug
and set Debug Port to9001
. -
Open
PHPStorm > Preferences > Languages & Frameworks > PHP > DBGp Proxy
and set Port to9001
. -
Open
PHPStorm > Preferences > Languages & Frameworks > PHP > Servers
and create a new server:- Set Name and Host to your domain name (ex.
shopware.test
) - Keep port set to
80
- Check the Path Mappings box and map
src
to the absolute path of/var/www/html
- Set Name and Host to your domain name (ex.
-
Go to
Run > Edit Configurations
and create a newPHP Remote Debug
configuration by clicking the plus sign and selecting it. Set the Name to your domain (ex.shopware.test
). Check theFilter debug connection by IDE key
checkbox, select the server you just setup, and under IDE Key enterPHPSTORM
. 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. -
Open up
src/public/index.php
, and set a breakpoint near the end of the file. Go toRun > Debug 'shopware.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.
Running Docker on Linux should be pretty straight-forward. Note that you need to run some post install commands as well as installing Docker Compose. These steps are taken care of automatically with Docker Desktop, but not on Linux.
You may have to increase a virtual memory map count on the host system. It is required by Elasticsearch.
Add following line to /etc/sysctl.conf
:
vm.max_map_count=262144
These docker images have built-in support for Blackfire.io. To use it, first register your server ID and token with the Blackfire agent:
bin/root blackfire-agent --register --server-id={YOUR_SERVER_ID} --server-token={YOUR_SERVER_TOKEN}
Next, open up the bin/start
helper script and uncomment the line:
#bin/root /etc/init.d/blackfire-agent start
Finally, restart the containers with bin/restart
. After doing so, everything is now configured and you can use a browser extension to profile your Magento store with Blackfire.
Where the most part of this config come from. Thanks for the awesome work Mark Shust.
The digital experience agency behind this repo. We are always open minded, strive for high quality and looking to improve our self. Tree Stones