Skip to content

Commit 1ec689b

Browse files
committed
Adapt domain name and SSL certs for Mac OS and Windows setups
Made some small adapaptions so the project does work when using docker-machine. - Use a local default snakeoil ssl cert: Not all systems have their snakeoil certs at /etc/ssl/certs/ssl-cert-snakeoil.pem - Changed the domain name from "127.0.0.1" to "dockerized-magento.local" in order to allow using the project with docker-machine on Mac OS and Windows - Removed the Vagrant file because docker-machine makes this obsolete - Add instructions for setting a hosts file entry (for Linux, Mac OS and Windows). - Add instructions for using docker-machine-nfs for better performance on Mac OS - Use more standard images to speed up the build - Add local volumes for logs and data - Update README section with stats action
1 parent d351c81 commit 1ec689b

23 files changed

+278
-182
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ composer.phar
44
vendor
55
db
66
.vagrant
7+
.DS_Store

Diff for: README.md

+64-37
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,59 @@ A dockerized version of "Magento Community Edition 1.9.x"
44

55
## Requirements
66

7-
Before you start you should install
7+
If you are on Linux you should install
88

99
- [docker](http://docs.docker.com/compose/install/#install-docker) and
1010
- [docker-compose (formerly known as fig)](http://docs.docker.com/compose/install/#install-compose)
1111

12-
or
12+
If you are running on [Mac OS](https://docs.docker.com/engine/installation/mac/) or [Windows](https://docs.docker.com/engine/installation/windows/) you can install the [Docker Toolbox](https://docs.docker.com/engine/installation/mac/) which contains docker, docker-compose and docker-machine.
1313

14-
You can use [vagrant](Vagrantfile) if you are on Windows or a Mac
14+
## Preparations
15+
16+
The web-server will be bound to your local ports 80 and 443. In order to access the shop you must add a hosts file entry for `dockerized-magento.local`.
17+
18+
### For Linux Users
19+
20+
In order to access the shop you must add the domain name "dockerized-magento.local" to your hosts file (`/etc/hosts`).
21+
If you are using docker **natively** you can use this command:
22+
23+
```bash
24+
sudo su
25+
echo "127.0.0.1 dockerized-magento.local" >> /etc/hosts
26+
```
27+
28+
### For Mac Users
29+
30+
If you are using [docker-machine](https://github.com/docker/machine) you need to use the IP address of your virtual machine running docker:
31+
32+
```bash
33+
docker-machine ls
34+
docker-machine ip <name-of-your-docker-machine>
35+
```
36+
37+
```bash
38+
echo "192.168.99.100 dockerized-magento.local" >> /etc/hosts
39+
```
40+
41+
**docker-machine performance**
42+
43+
For faster sync between your host system and the docker machine image I recommend that you activate NFS support for virtualbox: [github.com/adlogix/docker-machine-nfs](https://github.com/adlogix/docker-machine-nfs)
44+
45+
```bash
46+
docker-machine create --driver virtualbox nfsbox
47+
docker-machine-nfs nfsbox
48+
```
49+
50+
And to fix issues with filesystem permissions you can modify your NFS exports configuration:
51+
52+
1. open `/etc/exports` and replace `-mapall=$uid:$gid` with `-maproot=0`
53+
2. `sudo nfsd restart`
54+
55+
Thanks to [René Penner](https://github.com/renepenner/magento-docker-boilerplate) for figuring that out.
56+
57+
### For Windows Users
58+
59+
I suppose it will work on Windows, but I have not tested it. And I suspect that the performance will not be great due to the slow file-sharing protocol between the Windows hosts and the VirtualBox VM.
1560

1661
## Installation
1762

@@ -20,7 +65,7 @@ You can use [vagrant](Vagrantfile) if you are on Windows or a Mac
2065
3. Start the projects using `./magento start` or `docker-compose up`
2166

2267
```bash
23-
git clone https://github.com/andreaskoch/dockerized-magento.git && cd dockerized-magento
68+
git clone https://github.com/andreaskoch/dockerized-magento.local.git && cd dockerized-magento.local
2469
./magento start
2570
```
2671

@@ -35,19 +80,19 @@ During the first start of the project **docker-compose** will
3580
- import the sample database
3681
- and finally reindex all indices
3782

38-
Once the installation is fininished the installer will print the URL and the credentials for the backend to the installer log:
83+
Once the installation is finished the installer will print the URL and the credentials for the backend to the installer log:
3984

4085
```
4186
...
42-
installer_1 | Frontend: http://127.0.0.1/
43-
installer_1 | Backend: http://127.0.0.1/admin
87+
installer_1 | Frontend: http://dockerized-magento.local/
88+
installer_1 | Backend: http://dockerized-magento.local/admin
4489
installer_1 | - Username: admin
4590
installer_1 | - Password: password123
4691
```
4792

48-
[![Animation: Installation and first projec start](documentation/installation-and-first-start-animation.gif)](https://s3.amazonaws.com/andreaskoch/dockerized-magento/installation/Dockerized-Magento-Installation-Linux-no-sound.mp4)
93+
[![Animation: Installation and first project start](documentation/installation-and-first-start-animation.gif)](https://s3.amazonaws.com/andreaskoch/dockerized-magento.local/installation/Dockerized-Magento-Installation-Linux-no-sound.mp4)
4994

50-
**Note**: The build process and the installation process will take a while if you start the project for the first time. After thats finished starting and stoping the project will be a matter of seconds.
95+
**Note**: The build process and the installation process will take a while if you start the project for the first time. After that, starting and stoping the project will be a matter of seconds.
5196

5297
## Usage
5398

@@ -63,12 +108,13 @@ You can control the project using the built-in `magento`-script which is basical
63108
- **stop**: Stops all docker containers
64109
- **restart**: Restarts all docker containers and flushes the cache
65110
- **status**: Prints the status of all docker containers
111+
- **stats**: Displays live resource usage statistics of all containers
66112
- **magerun**: Executes magerun in the magento root directory
67113
- **composer**: Executes composer in the magento root directory
68114
- **enter**: Enters the bash of a given container type (e.g. php, mysql, ...)
69115
- **destroy**: Stops all containers and removes all data
70116

71-
**Note**: The `magento`-script is just a small wrapper arround `docker-compose`. You can just use [docker-compose](https://docs.docker.com/compose/) directly.
117+
**Note**: The `magento`-script is just a small wrapper around `docker-compose`. You can just use [docker-compose](https://docs.docker.com/compose/) directly.
72118

73119
## Components
74120

@@ -89,7 +135,7 @@ The dockerized Magento project consists of the following components:
89135

90136
The component-diagram should give you a general idea* how all components of the "dockerized Magento" project are connected:
91137

92-
[![Dockerized Magento: Component Diagram](documentation/dockerized-magento-component-diagram.png)](documentation/dockerized-magento-component-diagram.svg)
138+
[![Dockerized Magento: Component Diagram](documentation/dockerized-magento.local-component-diagram.png)](documentation/dockerized-magento.local-component-diagram.svg)
93139

94140
`*` The diagram is just an attempt to visualize the dependencies between the different components. You can get the complete picture by studying the docker-compose file: [docker-compose.yml](docker-compose.yml)
95141

@@ -109,37 +155,18 @@ If you have started the shop before you must **repeat the installation process**
109155

110156
### Changing the domain name
111157

112-
I set the default domain name to `127.0.0.1` so you can access the shop without modifying your hosts-file. But you can simply change that by replacing `127.0.0.1` with `your-domain.tld`.
113-
114-
The domain name used as the **base url** for the Magento installation is referenced three times in the docker-compose.yml:
158+
I set the default domain name to `dockerized-magento.local`. To change the domain name replace `dockerized-magento.local` with `your-domain.tld` in the `docker-compose.yml` file:
115159

116160
```yaml
117161
installer:
118162
environment:
119-
DOMAIN: 127.0.0.1
120-
nginx:
121-
domainname: 127.0.0.1
122-
environment:
123-
DOMAIN: 127.0.0.1
163+
DOMAIN: dockerized-magento.local
124164
```
125165
126-
1. In the `DOMAIN` environment variable for the **installer**
127-
2. In `domainname` attribute of the **nginx** container
128-
3. In the `DOMAIN` environment variable for the **nginx** container
129-
130-
### Using a different SSL certiticate
131-
132-
By default I chose the snakeoil dummy certificate that is installed on Ubuntu systems. If you are on a different system or want to use a real SSL certificate for your shop you can change the environment variables of the **nginx** container:
166+
### Using a different SSL certificate
133167
134-
- `SSL_CERTIFICATE_PATH` for the path to *.pem or *.crt file
135-
- `SSL_CERTIFICATE_KEY_PATH` for the path to the *.key file
136-
137-
```yaml
138-
nginx:
139-
environment:
140-
SSL_CERTIFICATE_PATH: <path-to-your-certificate>
141-
SSL_CERTIFICATE_KEY_PATH: <path-to-your-certificates-private-key>
142-
```
168+
By default I chose a dummy certificate ([config/ssl/cert.pem](config/ssl/cert.pem)).
169+
If you want to use a different certificate you can just override the key and cert with your own certificates.
143170
144171
### Adapt Magento Installation Parameters
145172
@@ -150,7 +177,7 @@ If you want to install Magento using your own admin-user or change the password,
150177
- `ADMIN_LASTNAME`: The last name of the admin user
151178
- `ADMIN_PASSWORD`: The password for the admin user
152179
- `ADMIN_EMAIL`: The email address of the admin user (**Note**: Make sure it has a valid syntax. Otherwise Magento will not install.)
153-
- `ADMIN_FRONTNAME`: The name of the backend route (e.g. `http://127.0.0.1/admin`)
180+
- `ADMIN_FRONTNAME`: The name of the backend route (e.g. `http://dockerized-magento.local/admin`)
154181

155182
```yaml
156183
installer:
@@ -166,7 +193,7 @@ installer:
166193

167194
### Change the MySQL Root User Password
168195

169-
I chose a very weak passwords for the MySQL root-user. You can change it by modifiying the respective environment variables for the **mysql-container** ... and **installer** because otherwise the installation will fail:
196+
I chose a very weak passwords for the MySQL root-user. You can change it by modifying the respective environment variables for the **mysql-container** ... and **installer** because otherwise the installation will fail:
170197

171198
```yaml
172199
installer:

Diff for: Vagrantfile

-40
This file was deleted.

Diff for: config/nginx/custom-locations/custom.location

Whitespace-only changes.

Diff for: config/nginx/includes/api

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Disable Basic Auth for the API
2+
location ~ ^/index\.php/api/ {
3+
rewrite .* /index.php break;
4+
5+
auth_basic off;
6+
expires off;
7+
8+
include /etc/nginx/includes/magento-fastcgi;
9+
include /etc/nginx/custom-includes/*-fastcgi;
10+
}

Diff for: config/nginx/includes/fastcgi

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
2+
3+
fastcgi_pass php:9000;
4+
fastcgi_index index.php;
5+
6+
include fastcgi_params;
7+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
8+
9+
fastcgi_param MAGENTO_ROOT /var/www/html/web;
10+
fastcgi_param REMOTE_ADDR $remote_addr;
11+
12+
fastcgi_buffer_size 1024k;
13+
fastcgi_buffers 500 512k;
14+
fastcgi_connect_timeout 1200;
15+
fastcgi_send_timeout 1200;
16+
fastcgi_read_timeout 1200;

Diff for: config/nginx/includes/gzip

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
gzip on;
2+
gzip_min_length 1000;
3+
gzip_proxied any;
4+
gzip_types text/plain
5+
application/xml
6+
text/css
7+
text/js
8+
application/javascript
9+
application/x-javascript;

Diff for: config/nginx/includes/minify

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
rewrite ^/minify/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
2+
rewrite ^/skin/m/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
3+
4+
location /lib/minify/ {
5+
allow all;
6+
}

Diff for: config/nginx/nginx.conf

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
user nginx;
2+
worker_processes 4;
3+
pid /var/run/nginx.pid;
4+
5+
events {
6+
worker_connections 1024;
7+
}
8+
9+
http {
10+
include /etc/nginx/mime.types;
11+
default_type application/octet-stream;
12+
13+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
14+
'$status $body_bytes_sent "$http_referer" '
15+
'"$http_user_agent" "$http_x_forwarded_for"';
16+
17+
access_log /var/log/nginx/access.log main;
18+
error_log /var/log/nginx/error.log warn;
19+
20+
sendfile on;
21+
keepalive_timeout 65;
22+
23+
include /etc/nginx/conf.d/*;
24+
}

Diff for: config/nginx/sites-enabled/default.conf

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
server {
2+
listen 80 default_server;
3+
listen 443 default_server ssl;
4+
5+
ssl_certificate /etc/nginx/ssl/cert.pem;
6+
ssl_certificate_key /etc/nginx/ssl/cert.key;
7+
8+
client_max_body_size 10M;
9+
10+
root /var/www/html/web;
11+
index index.php;
12+
13+
# Handle images directly
14+
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf)$ {
15+
root /var/www/html/web;
16+
}
17+
18+
location / {
19+
index index.html index.php;
20+
try_files $uri $uri/ @handler;
21+
expires 30d;
22+
}
23+
24+
location ^~ /app/ { deny all; }
25+
location ^~ /includes/ { deny all; }
26+
location ^~ /lib/ { deny all; }
27+
location ^~ /media/downloadable/ { deny all; }
28+
location ^~ /pkginfo/ { deny all; }
29+
location ^~ /report/config.xml { deny all; }
30+
location ^~ /var/ { deny all; }
31+
location ^~ /downloader/ { deny all; }
32+
location /var/export/ { deny all; }
33+
34+
# Custom Locations
35+
include /etc/nginx/custom-locations/*.location;
36+
37+
location ~ ^/cron\.(sh|php) {
38+
return 404;
39+
}
40+
41+
location /. {
42+
return 404;
43+
}
44+
45+
location @handler {
46+
rewrite / /index.php;
47+
}
48+
49+
location ~ \.php/ {
50+
rewrite ^(.*\.php)/ $1 last;
51+
}
52+
53+
54+
# All PHP Requests
55+
location ~ \.php$ {
56+
57+
## Catch 404s that try_files miss
58+
if (!-e $request_filename) {
59+
rewrite / /index.php last;
60+
}
61+
62+
include /etc/nginx/includes/fastcgi;
63+
}
64+
65+
include /etc/nginx/includes/minify;
66+
include /etc/nginx/includes/gzip;
67+
}

Diff for: config/ssl/cert.csr

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-----BEGIN CERTIFICATE REQUEST-----
2+
MIICoTCCAYkCAQAwXDELMAkGA1UEBhMCREUxEzARBgNVBAgTClNvbWUtU3RhdGUx
3+
GzAZBgNVBAoTEmRvY2tlcml6ZWQtbWFnZW50bzEbMBkGA1UEAxMSZG9ja2VyaXpl
4+
ZC1tYWdlbnRvMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzH4Ev70Y
5+
b4d6MJnmtDXysKMDvDq19vR5jAMtnNzrbbKnbBss0BtZfTA35OoKHJCkY2lFfVdF
6+
OW1Mw41srEtAcokAnEuO4XJ8rCrRdzCfLrvfIFDWlkg9RkdGtVm55L2UEOIY2j7Y
7+
GhcqSPXGEjfhiVom5YL5DVa5JCT0GyKj3aAN6eu9Bc9cuFcngJNgBzJAl/XKDktT
8+
VnsJOuG7hDPzD9ICcJos8Mm7cuocqK9l5Mw5EaCK+uqGBSZtkqf0v32iqXSjEQS0
9+
WyxHdC8WIGTH6DKZf1F+QgVZUv0MNCQlSvNzmKK7BVLhbpOxoRiwsT5Mps32Q409
10+
nccBzmwnByMTGwIDAQABoAAwDQYJKoZIhvcNAQEFBQADggEBACChDtUrxlfFNRbw
11+
vm6DwHSpBAZgee+5IoqXko76DpWTQzXTxxmZAY6IfvkJHPHlxkdYhojuEmPGfgWs
12+
EzQVrj/Ld8YeBleROtFSL6911dc2n41sFCTZUhZ2aP/RtzO/IX/fBhs/zAtGvKn/
13+
Z7gke5cD5D6/xhqIv7wngkxI4w54oS7y83ei1ZRpKqVhf6VM9vcmTPWXxPvYo2Bx
14+
HyvLLz8D7AEQ7kXKkv+YRFK1l11ca1GuGSf9I0jSJ3n43Gxt6Sk1MwrP0PyQBJh8
15+
+hbgr4neVAtFAXghC7Ky29qIrd8RxBWra1892gCzh4ie9nfHgQYgR4qhz5ebfS56
16+
PubY9ck=
17+
-----END CERTIFICATE REQUEST-----

0 commit comments

Comments
 (0)