Skip to content

Commit a2876ec

Browse files
author
Alan Kent
committed
More doc improvements.
Now syncs env.php file to make it easier to restart containers. Removed old environment variables. Darn, committed my keys by accident - invalidating and generating new ones.
1 parent 49e56fc commit a2876ec

File tree

3 files changed

+141
-70
lines changed

3 files changed

+141
-70
lines changed

README.md

Lines changed: 111 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ adjustments as described by comments in the file. This includes:
115115

116116
### 3. Launch the Containers
117117

118+
TODO: SOME FOLLOWING STEPS REQUIRE docker-compose.yml FILE CHANGES AND CHANGES
119+
INSIDE THE CONTAINERS AFTER BEING BUILT. THAT WOULD REQUIRE SPLITTING
120+
DESCRIPTIONS OF VARNISH ETC INTO TWO SECTIONS - STEPS TO DO BEFORE STARTING THE
121+
CONTAINERS AND STEPS TO DO AFTERWARDS.
122+
123+
TODO: SHOULD WE ADD A STEP DESCRIBING HOW TO SET UP A GIT REPO TO SHARE THE
124+
docker-compose.yml SETTINGS BETWEEN USERS?
125+
126+
It is recommended to read through all the following steps before launching the
127+
containers as described below. Some of the optional steps below require
128+
changes to the `docker-compose.yml` file, which requires rebuilding the
129+
containers to take effect. For example, Gulp and BrowserSync support requires
130+
opening up another port on the web service container. It is simpler to make
131+
these changes before starting up the containers.
132+
118133
Launch the containers by changing to the project directory and then running:
119134

120135
docker-compose up -d
@@ -192,6 +207,8 @@ TODO
192207

193208
**Internal Development**
194209

210+
TODO: THIS SECTION IS INDICATIVE OF FUTURE DIRECTION, NOT SUPPORTED YET.
211+
195212
This section is ONLY relevant to internal Magento developers, or external
196213
developers wishing to submit a pull request. The following is NOT recommended
197214
for production sites. (It may however be worth exploring by extension
@@ -246,7 +263,8 @@ The `mysql` command can now be used without arguments or selecting database.
246263
> exit;
247264

248265
Set up all the Magento 2 tables with the following command (adjusting command
249-
line paramter values as desired).
266+
line parameter values as desired). (See below for extra arguments if you wish
267+
to use RabbitMQ as well.)
250268

251269
magento setup:install --db-host=db --db-name=magento2 --db-user=root --db-password=root --admin-firstname=Magento --admin-lastname=Administrator --admin-email=user@example.com --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --backend-frontname=admin
252270

@@ -321,16 +339,6 @@ It is recommended to run the sync shell script in a separat Terminal window.
321339

322340
./m2devbox-unison-sync.sh
323341

324-
### 8. Connect with a Web Browser
325-
326-
Run the following command to determine the web server port number.
327-
328-
docker-compose port web 80
329-
330-
Be aware that in developer mode the slower PHP debug mode is on and missing
331-
CSS and similar files are created on demand. This means the first time you
332-
load a page you will see significantly longer load times.
333-
334342
### 9. Cron
335343

336344
Cron is disabled by default. Running cron may result in faster draining of
@@ -341,26 +349,78 @@ second cron to run)
341349
magento cron:run
342350
magento cron:run
343351

344-
To enable cron permanently run the following command.
352+
To enable cron permanently run the following shell script.
345353

346-
cat <<EOF | crontab -
347-
* * * * * /usr/local/bin/php /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log
348-
* * * * * /usr/local/bin/php /var/www/magento2/update/cron.php >> /var/www/magento2/var/log/update.cron.log
349-
* * * * * /usr/local/bin/php /var/www/magento2/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log
350-
EOF
354+
cron-install
351355

352-
### 10. Configure PHP Storm (if appropriate)
356+
### 8. Connect with a Web Browser
357+
358+
Run the following command to determine the web server port number to use when
359+
connecting to the web service container. (This can be different to the port
360+
number used inside the container.)
361+
362+
docker-compose port web 80
363+
364+
If the response is, for example, port 8080, connect to the web server store
365+
front using
366+
367+
http://localhost:8080/
368+
369+
Connect to the Magento Admin by appending `/admin` with username "admin" and
370+
password "admin123" (from the earlier `magento setup:install` command)
353371

372+
http://localhost:8080/admin
373+
374+
If you are running Docker inside VirtualBox, replace "localhost" with the IP
375+
address VirtalBox allocated to the VM Docker is running within.
376+
377+
Be aware that in developer mode the slower PHP debug mode is on and missing
378+
CSS and similar files are created on demand. This means the first time you
379+
load a page you will see significantly longer load times.
380+
381+
### 10. Configure PHP Storm (if appropriate)
354382
TODO: Script? SSH and Remote Interpreters?
355383

356384
### 11. Varnish Configuration
357385
TODO
386+
358387
### 12. Redis Configuration
359388
TODO
360-
### 13. Grunt Configuration
361-
TODO
362-
### 14. Gulp Configuration
363-
TODO
389+
390+
### 13. Grunt and Gulp Configuration
391+
392+
Grunt and Gulp are both frontend tool chains to speed up frontend development.
393+
They can both auto-recompile CSS files as soon as a file is written to disk.
394+
NodeJS is preinstalled in the web service container for use by Grunt and Gulp.
395+
396+
To enable Grunt support, run the following commands
397+
398+
cd /var/www/magento2
399+
cp Gruntfile.js.sample Gruntfile.js
400+
cp package.json.sample package.json
401+
npm install
402+
grunt refresh --force
403+
404+
For further details, please refer to the Grunt section in the "Frontend
405+
Developer Guide" on http://devdocs.magento/com.
406+
407+
Magento does not ship with default Gulp support, but there is the excellent
408+
"frontools" community project based on Gulp. Frontools can be found at
409+
https://github.com/SnowdogApps/magento2-frontools. Version 0.11.4 was the last
410+
version with Less support (as supported by Magento). Frontools provides Sass
411+
replacements for the blank theme that they now support.
412+
413+
If frontools is not suitable, there are numerous other articles on the web
414+
explaining how to set up Gulp support such as
415+
https://alankent.me/2016/01/27/gulp-et-al-in-magento-2/. Magento provides a
416+
`magento dev:source-theme:deploy` command that resolves all of the Magento file
417+
fallback rules, allowing Gulp or other similar pipelines to be run on the
418+
resultant directory tree.
419+
420+
If you wish to run BrowserSync with Gulp (https://www.browsersync.io/), you
421+
will also need to edit the `docker-compose.yml` file to add the BrowserSync
422+
port number to the "ports" list to expose. For this to take effect, you must
423+
rebuild the container which will wipe all the files in the container.
364424

365425
# Tips and Tricks
366426

@@ -385,24 +445,46 @@ Restart the containers later with
385445
If you are using Unison, remember to also restart Unison for file syncing
386446
to work.
387447

388-
When you no longer need the container, you can kill and remove it. THIS WILL
389-
WIPE ALL FILES INSIDE THE CONTAINER, LOSING ANY CHANGES FOREVER. It will not
390-
remove the locally synchronized files under the `shared` directory.
448+
## Removing and Rebuilding Containers
449+
450+
When you no longer need the DevBox, you can kill and remove all of the running
451+
containers. THIS WILL WIPE ALL FILES INSIDE THE WEB CONTAINER AND THE DATABASE,
452+
LOSING ANY CHANGES FOREVER. It will not remove any locally synchronized files
453+
under the `shared` directory.
391454

392455
docker-compose kill
393456
docker-compose rm
394457

395458
If you decide to change the settings in `docker-composer.yml` after the
396-
containers have been created, you will need to remove the current containers
397-
and recreate them (including the database contents). MAKE SURE THE SOURCE CODE
398-
IS UP TO DATE UNDER THE `shared/www` DIRECTORY BEFORE DELETING THE CONTAINERS
399-
TO MAKE SURE YOU DO NOT ACCIDENTALLY LOSE ANY OF YOUR WORK.
459+
containers have been created, you will need to rebuild the containers.
460+
MAKE SURE THE SOURCE CODE IS UP TO DATE UNDER THE `shared/www` DIRECTORY ON
461+
YOUR LAPTOP BEFORE REBUILDING THE CONTAINERS TO MAKE SURE YOU DO NOT
462+
ACCIDENTALLY LOSE ANY OF YOUR WORK.
463+
464+
There are two strategies you can use. The first is to delete all the containers
465+
as above and then recreate them. This will delete the database contents as
466+
well.
400467

401468
docker-compose kill
402469
docker-compose rm
403470
# Make changes to docker-compose.yml
404471
docker-compose up -d
405472

473+
If you are using Unison file syncing, when you restart Unison locally it will
474+
copy all the code from `shared/www` back into the `/var/www` directory inside
475+
the container. After that, `magento setup:install` can be run to rebuild the
476+
database.
477+
478+
The second approach is to use the `--build` option of Docker Compose which
479+
will only rebuild affected containers. For example, if opening up a new port
480+
to the web service container, using `--build` will not remove the database
481+
container, preserving its contents. When the `/var/www` directory is restored
482+
(via Unison or Volume mounting) the database connection settings (in `env.php`)
483+
will also be restored.
484+
485+
# Make changes to docker-compose.yml
486+
docker-compose up -d --build
487+
406488
## Kitematic
407489

408490
If you like GUIs, you may wish to install Kitematic from the Docker site as

docker-compose.yml

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,65 +35,55 @@ services:
3535
#- "./shared/.magento-cloud:/home/magento2/.magento-cloud"
3636

3737
environment:
38-
# TODO: Prune back these variables.
39-
- SHARED_CODE_PATH="/home/magento2/magento2"
40-
- USE_RABBITMQ=0
41-
- USE_REDIS_FULL_PAGE_CACHE=0
42-
- USE_REDIS_CACHE=0
43-
- USE_REDIS_SESSIONS=0
44-
- USE_VARNISH=0
45-
- USE_ELASTICSEARCH=0
46-
- MAGENTO_PUBLIC_KEY=57db5595af2135685cc2c96af1be707b
47-
- MAGENTO_PRIVATE_KEY=9d74dca55383dcaf6b03d91cea09ecad
48-
- MAGENTO_USE_SOURCES_IN_HOST=0
49-
- CREATE_SYMLINK_EE=0
50-
- HOST_CE_PATH=./shared/webroot
51-
- EE_DIRNAME=magento2ee
52-
- MAGENTO_DOWNLOAD_SOURCES_COMPOSER=1
53-
- MAGENTO_EDITION=ce
54-
- MAGENTO_VERSION=2.2.0-rc21
55-
- MAGENTO_SAMPLE_DATA_INSTALL=1
56-
- MAGENTO_DOWNLOAD_SOURCES_CLOUD=0
57-
- MCLOUD_USERNAME=
58-
- MCLOUD_PASSWORD=
59-
- MCLOUD_GENERATE_NEW_TOKEN=
60-
- MCLOUD_PROJECT=
61-
- MCLOUD_BRANCH=
62-
- MAGENTO_CRON_RUN=0
63-
- MAGENTO_DI_COMPILE=0
64-
- MAGENTO_GRUNT_COMPILE=0
65-
- MAGENTO_STATIC_CONTENTS_DEPLOY=0
66-
- MAGENTO_BACKEND_PATH=admin
67-
- MAGENTO_ADMIN_USER=admin
68-
- MAGENTO_ADMIN_PASSWORD=admin123
38+
# Optional. If set, container will create a default auth.json
39+
# file for Composer to use (if one does not already exist).
40+
#- MAGENTO_PUBLIC_KEY=<insert-hex-key-here>
41+
#- MAGENTO_PRIVATE_KEY=<insert-hex-key-here>
42+
43+
# The following exposes ports inside the container publicly.
44+
# Docker maps the public port numbers to ports inside the container
45+
# using Linux iptables support. If a single number is specified,
46+
# Docker will pick an unused port number at random every time the
47+
# container restarts. Use 8080:80 to bind the public port number
48+
# of 8080 to the internal port number of 80. (The internal port
49+
# number never changes - you may pick any external port number
50+
# to avoid collisions between different containers or projects.)
6951
ports:
7052

71-
# Pick a random unused web server port. (Use 8080:80 for a fixed
72-
# port number.)
53+
# Pick a random unused web server port.
54+
# (Use 8080:80 for force external port to be 8080.)
7355
- 80
7456

75-
# Pick a random SSH port. (Use 22:22 to force it to be 22 locally.)
57+
# The SSH port.
7658
- 22
7759

78-
# Pick a random unused Unison port.
79-
# (Can be commented out if not using Unison.)
60+
# Pick a random unused unison port.
61+
# (Only needed if using Unison for file syncing.)
8062
- 5000
8163

64+
# Default BrowserSync ports.
65+
# (Only needed if using BrowserSync for frontend development.)
66+
- 3000
67+
- 3001
68+
8269
db:
8370
container_name: proj1-m2db
8471
restart: always
8572
image: mysql:5.6
73+
8674
ports:
8775
- "3306"
76+
8877
environment:
8978
- MYSQL_ROOT_PASSWORD=root
9079
- MYSQL_DATABASE=magento2
91-
volumes:
9280

93-
# Uncomment if you want the database to live after removing the
94-
# containers. (Not recommended, can be confusing.)
95-
#- "./shared/db:/var/lib/mysql"
81+
volumes:
9682

9783
# Uncomment to mount log files locally.
9884
#- "./shared/logs/mysql:/var/log/mysql"
9985

86+
# Uncomment if you want the database to last after removing the
87+
# container. (Not recommended.)
88+
#- "./shared/db:/var/lib/mysql"
89+

m2devbox-unison-sync.bat

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ REM Magento files not worth pulling locally.
3232
@SET IGNORE=%IGNORE% -ignore "Path magento2/var/.update_cronjob_status"
3333
@SET IGNORE=%IGNORE% -ignore "Path magento2/pub/media"
3434
@SET IGNORE=%IGNORE% -ignore "Path magento2/pub/static"
35-
@SET IGNORE=%IGNORE% -ignore "Path magento2/app/etc/env.php"
3635

3736
REM Other files not worth pushing to the container.
3837
@SET IGNORE=%IGNORE% -ignore "Path magento2/.git"

0 commit comments

Comments
 (0)