Skip to content

Commit 658f960

Browse files
committed
2 parents 1ecc388 + 5e8714f commit 658f960

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

Diff for: README.md

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Magento2 (Varnish + PHP7 + Redis) docker-compose infrastructure
2+
3+
## Infrastructure overview
4+
* Container 1: MariaDB
5+
* Container 2: Redis (we'll use it for Magento's cache)
6+
* Container 3: Apache 2.4 + PHP 7 (modphp)
7+
* Container 4: Cron
8+
* Container 5: Varnish 4
9+
10+
###Why a separate cron container?
11+
First of all containers should be (as far as possible) single process, but the most important thing is that (if someday we'll be able to deploy this infrastructure in production) we may need a cluster of apache+php containers but a single cron container running.
12+
13+
Plus, with this separation, in the context of a docker swarm, you may be able in the future to separare resources allocated to the cron container from the rest of the infrastructure.
14+
15+
## Downloading Magento2
16+
```
17+
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
18+
```
19+
20+
## Do you want sample data?
21+
Execute (from the host machine):
22+
```
23+
cd magento2
24+
php bin/magento sampledata:deploy
25+
composer update
26+
```
27+
You can lunch the same commmands from within the container, it's actually the same thing
28+
29+
## Starting all docker containers
30+
```
31+
docker-compose up -d
32+
```
33+
The fist time you run this command it's gonna take some time to download all the required images from docker hub.
34+
35+
## Install Magento2
36+
37+
open your browser to the address:
38+
```
39+
http://magento2.docker/
40+
```
41+
and use the wizard to install Magento2.
42+
43+
## Deploy static files
44+
```
45+
docker exec -it dockermagento2_apache_1 bash
46+
php bin/magento dev:source-theme:deploy
47+
php bin/magento setup:static-content:deploy
48+
```
49+
50+
## Enable Redis for Magento's cache
51+
open magento2/app/etc/env.php and add these lines:
52+
```php
53+
'cache' => array(
54+
'frontend' => array(
55+
'default' => array(
56+
'backend' => 'Cm_Cache_Backend_Redis',
57+
'backend_options' => array(
58+
'server' => 'redis',
59+
'port' => '6379',
60+
'persistent' => '', // Specify a unique string like "cache-db0" to enable persistent connections.
61+
'database' => '0',
62+
'password' => '',
63+
'force_standalone' => '0', // 0 for phpredis, 1 for standalone PHP
64+
'connect_retries' => '1', // Reduces errors due to random connection failures
65+
'read_timeout' => '10', // Set read timeout duration
66+
'automatic_cleaning_factor' => '0', // Disabled by default
67+
'compress_data' => '1', // 0-9 for compression level, recommended: 0 or 1
68+
'compress_tags' => '1', // 0-9 for compression level, recommended: 0 or 1
69+
'compress_threshold' => '20480', // Strings below this size will not be compressed
70+
'compression_lib' => 'gzip', // Supports gzip, lzf and snappy,
71+
'use_lua' => '0' // Lua scripts should be used for some operations
72+
)
73+
),
74+
'page_cache' => array(
75+
'backend' => 'Cm_Cache_Backend_Redis',
76+
'backend_options' => array(
77+
'server' => 'redis',
78+
'port' => '6379',
79+
'persistent' => '', // Specify a unique string like "cache-db0" to enable persistent connections.
80+
'database' => '1', // Separate database 1 to keep FPC separately
81+
'password' => '',
82+
'force_standalone' => '0', // 0 for phpredis, 1 for standalone PHP
83+
'connect_retries' => '1', // Reduces errors due to random connection failures
84+
'lifetimelimit' => '57600', // 16 hours of lifetime for cache record
85+
'compress_data' => '0' // DISABLE compression for EE FPC since it already uses compression
86+
)
87+
)
88+
)
89+
),
90+
```
91+
and delete all Magento's cache with
92+
```
93+
rm -rf magento2/var/cache/*
94+
```
95+
from now on the var/cache directory should stay empty cause all the caches should be stored in Redis.
96+
97+
## Enable Varnish
98+
Varnish Full Page Cache should already be enabled out of the box (we startup Varnish with the default VCL file generated by Magento2) but you could anyway go to "stores -> configuration -> advanced -> system -> full page cache" and:
99+
* select Varnish in the "caching application" combobox
100+
* type "apache" in both "access list" and "backend host" fields
101+
* type 80 in the "backend port" field
102+
* save
103+
104+
# Cross platform and performance
105+
106+
At the moment the apache/php container has been created in order to work with the default Docker Machine, to be able to run on both windows and mac (check the usermod 1000 in the Dockerfile).
107+
108+
Performarce are not ok on a good hardware but everybody knows about vbox shared folders slowness...
109+
110+
On mac is surely better to use Dinghy as a replacement for the default Docker Machine but the problem is that I would have need to generate the apache/php image with "usermod 501" making it not compatible with the default Docker Machine and thus windows devs.
111+
112+
What's the better choice? Please share your ideas with me.
113+
114+
# TODO
115+
* Support for scaling the apache container(s) via "docker-compose scale apache=X", with Vanirsh backends auto discovery
116+
* Add a SSL terminator image
117+
* DB clustering?

0 commit comments

Comments
 (0)