Skip to content

Commit c651266

Browse files
author
Alan Kent
committed
Further simplifications.
1 parent 212ce72 commit c651266

File tree

2 files changed

+80
-145
lines changed

2 files changed

+80
-145
lines changed

README.md

Lines changed: 78 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ container (holding the Magento source code). Other containers can be added as
1818
required for Varnish (recommended), Redis, RabbitMQ, and ElasticSearch. All
1919
containers run Linux inside.
2020

21-
The container developers interact with the most is the web container. The
22-
other containers are relatively shrink wrap.
21+
Developers mainly interact with the web container. The other containers are
22+
relatively shrink wrap.
2323

2424
Normally you set up containers and use them for a long time, removing them only
2525
when no longer required. Containers can be 'stopped' without being 'removed' to
@@ -34,7 +34,8 @@ Mac and Windows cannot directly access the file system inside the web container
3434
Storm has special support for "remote PHP interpeters" via ssh. This makes
3535
source code development and debugging using PHP Storm relatively painless
3636
even when PHP and the web server are running inside a Docker container.
37-
However, PHP Storm does need access to the the source code.
37+
However, PHP Storm does need access to the the source code for editing and
38+
debugging.
3839

3940
* There are several directories (such as log directories) which you can choose
4041
to mount via Docker volumes for easy access directly from your laptop. These
@@ -46,89 +47,61 @@ Mac and Windows cannot directly access the file system inside the web container
4647
"iNotify" file system events. Volume mounting on Windows does not support
4748
iNotify events at this time.
4849

49-
Where volume mounts are not suitable (that is, the Magento source code on Mac
50-
and Windows), DevBox syncs the local and container file systems using a program
51-
called Unison. Whenver a file in the watched local file system is changed, it
52-
is coped into the web container, and vice versa. This allows IDEs to be
53-
natively used on a laptop (or desktop) - Unison copies file changes as soon as
54-
they are made into the web conatiner.
50+
Where volume mounts are not suitable (that is, the Magento source code
51+
directory on Mac and Windows), DevBox syncs the local and container file
52+
systems using a program called Unison. Whenver a file in the watched local file
53+
system is changed, it is coped into the web container, and vice versa. This
54+
allows IDEs to be natively used on a laptop (or desktop) - Unison copies file
55+
changes as soon as they are written to disk into the web conatiner.
5556

56-
**Enabling Volume Mounts**
57-
58-
To enable volume mounting for the Magento source code (e.g. for Linux laptops),
59-
uncomment the relevant volume mount line for `/var/www` in the provided
60-
`docker-compose.yml` file. For Unison (e.g. for Mac and Windows), ensure the
61-
line is commented out.
62-
63-
**Enabling Unison**
64-
65-
For Windows, a BAT file is provided with the appropriate command line options
66-
to run Unison. For Mac, a shell script is provided. The scripts will restart
67-
Unison automatically if the web container is restarted for some reason.
68-
The script also does an optimized first pass to reduce noise on the console
69-
(it normally reports every synchronized file).
70-
71-
On Windows, the easiest way to launch Unison is to run the Unison BAT file
72-
in its own window using the START command or by double clicking on the BAT
73-
file from Windows file explorer.
74-
75-
START m2devbox-unison-sync.bat
76-
77-
On Mac, it is recommended to run the script in a separate Terminal window.
78-
79-
./m2devbox-unison-sync.sh
80-
81-
# Getting Started
57+
# Installation
8258

8359
Now you understand what file syncing approach you are going to use, you are now
8460
ready to get up and going with DevBox.
8561

8662
## Prerequisites
8763

8864
* Install a recent version of Docker from http://docker.com/. Docker is
89-
available for Windows, Mac, and Linux. Volume mounting (described below)
90-
is not recommended for older versions of Docker or when using Docker inside
91-
VirtualBox on Windows.
65+
available for Windows, Mac, and Linux.
9266
* As part of the Docker installation process, on Windows 10 you may need to
9367
turn on Hyper-V and then grant Docker access to the `C:` drive for Docker to
9468
mount volumes correctly. This is described in the Docker documentation.
95-
Please note that turning on Hyper-V disables VirtualBox. If you run Docker
96-
in VirtualBox, please be aware that VirtualBox will have its own IP address
97-
(unlike Docker running in Hyper-V that default is accessed using
98-
"localhost").
9969
* On Windows, it can be useful to install "Git Bash"
10070
(https://git-for-windows.github.io/). As well as Git, it includes a terminal
101-
emulator that works well with Docker as well as a small collection of Linux
102-
commands.
71+
emulator as well as a useful collection of Linux commands.
10372

10473
## Setting Up a New Environment
10574

10675
### 1. Create a Local Project Directory
10776

108-
To start a new project, download a copy of the files in this project to a
109-
new empty directory. Normally you create a directory per project. (Developers
110-
at an system integrator or agency may work on multiple projects at once, one
111-
directory per project.) This project holds starter files for your project.
112-
113-
GitHub provides a "download ZIP" option if you don't have git installed
114-
locally.
77+
Create a new directory per project. Download a copy of the files in this
78+
project to a empty directory.
11579

116-
* TODO: http://github.com/alankent/magento2devbox-skeleton
80+
* Go to http://github.com/alankent/magento2devbox-skeleton
81+
* In the "Branch" drop down, select the tag closest to the project's version
82+
of Magento. This is to get the correct version of PHP, MySQL, etc.
11783
* Click on the green button "Clone or Download" and select "Download ZIP".
118-
* Extract the ZIP file contents into an empty directory.
84+
* Extract the ZIP file contents into the project directory.
11985

12086
### 2. Review and Update the docker-compose.yml File
12187

122-
Review the `docker-compose.yml` file in a text editor for adjustments such as
123-
preferred local port numbers. There are comments in the file describing
124-
the settings you are most likely to change.
88+
Review the `docker-compose.yml` file in a text editor, making necessary
89+
adjustments as described by comments in the file. This includes:
90+
91+
* You MUST ensure the container names are different per project to avoid
92+
conflicts. For example, the default web service container name is
93+
"proj1-m2web" and the default db service container name is "proj1-m2db".
94+
Change all occurrences of "proj1" to your project name.
12595

126-
If you work on multiple projects, create a separate directory per project (e.g.
127-
"proj1", "proj2", etc). DevBox is not designed to switch between projects. You
128-
must ensure the container names are different per project to avoid conflicts.
129-
For example, the default web container name is "m2web" (NOT "web") and the
130-
default database container is "m2db". Change these to "proj1-m2web" and
131-
"proj1-m2db" to match your project name.
96+
* To enable volume mounting for the Magento source code (e.g. for Linux
97+
laptops), uncomment the volume mount line for `/var/www` in the provided
98+
`docker-compose.yml` file. For Unison (e.g. for Mac and Windows), ensure the
99+
line is commented out.
100+
101+
* Check the port numbers. By default Docker will allocate random free port
102+
numbers. Change "80" to "8080:80" if you want the web server port to be
103+
always 8080. You cannot run different containers at the same time using
104+
the same port numbers.
132105

133106
### 3. Launch the Containers
134107

@@ -142,55 +115,30 @@ To get a bash prompt inside the web container, use
142115

143116
You should see a shell prompt of `m2$`.
144117

145-
You can check what containers are running using
146-
147-
docker ps
148-
149-
You can also see what containers exist but are currently not running using
118+
You can check what containers exist using
150119

151120
docker ps -a
152121

153122
### 4. Composer Configuration
154123

155-
This section is optional, but includes Composer performance optimizations worth
156-
considering if you work on multiple projects.
157-
158124
The recommended way to create and update projects is via Composer, a PHP
159125
package manager. Magento provides a Composer repository from which Magento
160126
(and extensions purchased from Magento Marketplace) can be downloaded.
161127

162-
There is also a Magento ZIP download which is faster to download, but you will
163-
need to use Composer at some stage to install patches or extensions, so it is
164-
recommended to start with Composer from day 1.
165-
166-
Composer supports a download cache. Having this mounted to a local directory on
167-
your laptop allows downloads to be shared betwen containers. Cached downloads
168-
make subsequent upgrades and new installs much faster. If you do not mount a
169-
shared volume for this directory, you cannot share the cache between containers
170-
and the cache will be lost when the container is removed. There is nothing
171-
wrong with this other than a potentially larger network bill for downloads and
172-
slower startup time for subsequent new projects.
173-
174-
Be aware the Composer can be slow to run at times. Give it a minute or two even
175-
if no output is occurring.
176-
177-
DevBox sets the `COMPOSER_HOME` environment variable to
178-
`/home/magento2/.composer`.
128+
Composer caches downloads for performance. Mounting the cache directory on your
129+
laptop is enabled by uncommenting the "~/.composer" volume mount in the
130+
`docker-compose.yml` file. This allows downloads to be shared betwen containers
131+
(e.g. on different projects). If you do not mount a directory, the cache will
132+
discarded when the container is removed.
179133

180134
The first time you run Composer, it may prompt you for a username and password.
181135
Enter your 'public' and 'private' keys from http://marketplace.magento.com/,
182-
"My Profile", "Access keys" when prompoted. Just be aware that an `auth.json`
136+
"My Profile", "Access keys" when prompoted. Be aware that an `auth.json`
183137
file holding your keys will be saved into `~/.composer/`. You may want to share
184138
the Composer downloaded files but have a different `auth.json` file per project
185139
by moving the `auth.json` file into your project's home directory (but not
186140
committing this file to git for security reasons).
187141

188-
To summarize, the easiest thing is to do nothing - not mount a shared composer
189-
repository. For those wanting the improved performance, it is recommended to
190-
uncomment the line in the `docker-compose.yml` file to volume mount the
191-
`/home/magento2/.composer` directory. Manually create ~/.composer on your
192-
laptop if it does not already exist.
193-
194142
### 5. Install Magento
195143

196144
Next you need to install your Magento project inside the web container under
@@ -202,25 +150,24 @@ the `/var/www/magento2` directory. (Apache is configured by default to use
202150
If you have an existing project with all the source code already under
203151
`shared/www`, you can skip this section. If you use volume mounting, the code
204152
will automatically be visible; if you use Unison, it will copy files on your
205-
laptop into the web container when Unison is started. Not additional
153+
laptop into the web container when Unison is started. No additional
206154
configuration is required.
207155

208-
Note: If you decide to change the settings in `docker-composer.yml` after
209-
the containers have been created, you will need to remove the current
210-
containers and recreate them. This falls under the 'existing project' use case.
211-
MAKE SURE THE SOURCE CODE IS UP TO DATE UNDER THE `shared/www` DIRECTORY BEFORE
212-
DELETING THE CONTAINERS TO MAKE SURE YOU DO NOT ACCIDENTALLY LOSE ANY OF YOUR
213-
WORK.
214-
215-
**Creating a New Project**
156+
Note: If you decide to change the settings in `docker-composer.yml` after the
157+
containers have been created, you will need to remove the current containers
158+
and recreate them (including the database contents). This falls under the
159+
'existing project' use case. MAKE SURE THE SOURCE CODE IS UP TO DATE UNDER THE
160+
`shared/www` DIRECTORY BEFORE DELETING THE CONTAINERS TO MAKE SURE YOU DO NOT
161+
ACCIDENTALLY LOSE ANY OF YOUR WORK.
216162

217-
The following commands create a new, default, project.
163+
**Creating a New Project with Composer**
218164

219-
First log into the web container.
165+
Log into the web container.
220166

221167
docker-compose exec web bash
222168

223-
Then create a new project under `/var/www/magento2`. Update the project version number below as appropriate.
169+
Create a new project under `/var/www/magento2`. (Update the project version
170+
number as appropriate.)
224171

225172
mkdir /var/www/magento2
226173
cd /var/www/magento2
@@ -229,9 +176,8 @@ Then create a new project under `/var/www/magento2`. Update the project version
229176

230177
**Getting Code from a GitHub Project**
231178

232-
Saving your code in a private git repository on a hosting provider such as
233-
GitHub or BitBucket is strongly recommended. Project structures can change
234-
between developers, but the following is a possible example.
179+
It is strongly recommended to saving your project code in a private git
180+
repository on a hosting provider such as GitHub or BitBucket.
235181

236182
Log into the web container:
237183

@@ -241,7 +187,7 @@ Check out the project from inside the container into the `magento2` directory.
241187

242188
cd /var/www
243189
git clone https://github.com/mycompany/myproject.git magento2
244-
cd /var/www/magento2
190+
cd magento2
245191
composer install
246192

247193
**Magento Commerce (Cloud)**
@@ -250,9 +196,10 @@ TODO
250196

251197
**Internal Development**
252198

253-
This section is relevant to internal Magento developers, or external developers
254-
wishing to submit a pull request. The following is NOT recommended for
255-
production sites. (It may however be worth exploring by extension developers.)
199+
This section is ONLY relevant to internal Magento developers, or external
200+
developers wishing to submit a pull request. The following is NOT recommended
201+
for production sites. (It may however be worth exploring by extension
202+
developers.)
256203

257204
Log into the web container:
258205

@@ -287,43 +234,38 @@ Tun the following commands to create a MyQL database to use.
287234

288235
mysql -e 'CREATE DATABASE IF NOT EXIST magento2;'
289236

290-
After the database is created, you can uncomment the line setting the default
291-
database in the MySQL `~/.my.cnf` file so that when you run `mysql` from the
292-
command prompt it will log you in and select the `magento2` database by
293-
default. (If this is set when the database does not exist, `mysql` will fail to
294-
start.) This is not mandatory, but is convenient.
237+
After the database is created, uncomment the line setting the default
238+
database in the MySQL `~/.my.cnf` file.
295239

240+
sed -e 's/#database/database/' -i ~/.my.cnf
296241
mysql
297242
> SHOW TABLES;
298243
> exit;
299244

300-
Next, put the site into developer mode.
245+
Put the site into developer mode.
301246

302247
cd /var/www/magento2
303248
magento deploy:mode:set developer
304249

305250
Set up all the Magento 2 tables with the following command (adjusting command
306251
line paramter values as desired).
307252

308-
cd /var/www/magento2
309253
magento setup:install --db-host=db --db-name=magento2 --db-user=root --db-password=magento2 --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
310254

311255
It is recommended to NOT include the `--base_url` option during development as
312256
Docker can allocate a port number at random (including when container is
313257
restarted). It also causes problems using BrowserSync and similar tools for
314-
frontend development. (Some versions of Magento however have a bug requiring
258+
frontend development. Some versions of Magento however have a bug requiring
315259
`--base_url` to be specified. If the URL to CSS files is incorrect, you may
316-
have a broken version of Magento.)
260+
have a broken version of Magento.
317261

318262
If you are using RabbitMQ (AMPQ), the following command line arguments should
319263
be added when the project is created.
320264

321265
--amqp-virtualhost=/ --ampq-host=ampq --amqp-port=TODO --amqp-user=guest --amqp-password=guest
322266

323-
If you want to load the Luma sample data (optional), run the following
324-
additional commands.
267+
To load the Luma sample data (optional), run the following additional commands.
325268

326-
cd /var/www/magento2
327269
magento sampledata:deploy
328270
magento setup:upgrade
329271

@@ -334,29 +276,27 @@ process (and keep it running). It is generally recommended to start this up
334276
after you have installed Magento above.
335277

336278
On Windows, get a compatible version of the Unison binaries for Windows
337-
from inside the container using the following (adjust "m2web" to your
338-
web container name from the `docker-compose.yml` file - there is no
339-
`docker-compose cp` command at this time so you cannot use "web", the service
340-
name).
279+
from inside the container using the following (adjust "proj1-m2web" to your
280+
web container name from the `docker-compose.yml` file).
341281

342-
docker cp m2web:/windows/unison.exe .
343-
docker cp m2web:/windows/unison-fsmonitor.exe .
282+
docker cp proj1-m2web:/windows/unison.exe .
283+
docker cp proj1-m2web:/windows/unison-fsmonitor.exe .
344284

345-
Then run the supplied BAT file in a separate window using the START command or
346-
by double clicking via Windows explorer. Close the window to kill Unison.
285+
Then run the supplied BAT file to launch Unison in a separate window using the
286+
START command or by double clicking the BAT file via Windows explorer. Close
287+
the window to kill Unison.
347288

348289
START m2devbox-unison-sync.bat
349290

350291
Each time you log in, make sure you restart this process, but be careful to not
351-
have multiple copies running. If you stop work on the project, you can close
352-
this window and start it up again later. It is not recommended to do
292+
have multiple copies running in parallel. It is not recommended to do
353293
significant work on the project without Unison running to avoid merge conflicts
354294
(rare).
355295

356296
Mac binaries and a shell script are also provided:
357297

358-
docker cp m2web:/macos/unison .
359-
docker cp m2web:/macos/unison-fsmonitor .
298+
docker cp proj1-m2web:/macos/unison .
299+
docker cp proj1-m2web:/macos/unison-fsmonitor .
360300
chmod +x unison unison-fsmonitor
361301

362302
It is recommended to run the sync shell script in a separat Terminal window.
@@ -365,12 +305,7 @@ It is recommended to run the sync shell script in a separat Terminal window.
365305

366306
### 8. Connect with a Web Browser
367307

368-
To access the web server, if you set the web port using the {localport}:80
369-
syntax (e.g. 8080:80), access the page using the specified localport (e.g.
370-
http://localhost:8080/). If you did not specify a local port, a random port
371-
that is not currently in use will be allocated by Docker. You can use
372-
`docker-compose` with the server name "web" to fetch the local port number
373-
that is bound to the web server port.
308+
Run the following command to determine the web server port number.
374309

375310
docker-compose port web 80
376311

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
version: '2'
77
services:
88
web:
9-
container_name: m2web
9+
container_name: proj1-m2web
1010
restart: always
1111
image: magento2devbox-web:latest
1212
volumes:
@@ -74,7 +74,7 @@ services:
7474
- 5000
7575

7676
db:
77-
container_name: m2db
77+
container_name: proj1-m2db
7878
restart: always
7979
image: mysql:5.6
8080
ports:

0 commit comments

Comments
 (0)