Skip to content

Commit dc5a7db

Browse files
committed
Upgrade 2.0 branch
2 parents a5b4daf + 97831a4 commit dc5a7db

28 files changed

+631
-37
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.bash_history
2+
node_modules

Dockerfile.hbs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
FROM alexcheng/apache2-php7:{{phpVersion}}
2+
3+
LABEL maintainer="[email protected]"
4+
LABEL version="{{magento2Version}}"
5+
LABEL description="Magento {{magento2Version}}"
6+
7+
ENV MAGENTO_VERSION {{magento2Version}}
8+
ENV INSTALL_DIR /var/www/html
9+
ENV COMPOSER_HOME /var/www/.composer/
10+
11+
RUN curl -sS https://getcomposer.org/installer | php \
12+
&& mv composer.phar /usr/local/bin/composer
13+
COPY ./auth.json $COMPOSER_HOME
14+
15+
RUN requirements="libpng12-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 libjpeg-turbo8 libjpeg-turbo8-dev libpng12-dev libfreetype6-dev libicu-dev libxslt1-dev" \
16+
&& apt-get update \
17+
&& apt-get install -y $requirements \
18+
&& rm -rf /var/lib/apt/lists/* \
19+
&& docker-php-ext-install pdo_mysql \
20+
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
21+
&& docker-php-ext-install gd \
22+
&& docker-php-ext-install mcrypt \
23+
&& docker-php-ext-install mbstring \
24+
&& docker-php-ext-install zip \
25+
&& docker-php-ext-install intl \
26+
&& docker-php-ext-install xsl \
27+
&& docker-php-ext-install soap \
28+
&& requirementsToRemove="libpng12-dev libmcrypt-dev libcurl3-dev libpng12-dev libfreetype6-dev libjpeg-turbo8-dev" \
29+
&& apt-get purge --auto-remove -y $requirementsToRemove
30+
31+
RUN chsh -s /bin/bash www-data
32+
33+
{{{magento2Installation}}}
34+
35+
RUN cd $INSTALL_DIR \
36+
&& find . -type d -exec chmod 770 {} \; \
37+
&& find . -type f -exec chmod 660 {} \; \
38+
&& chmod u+x bin/magento
39+
40+
COPY ./install-magento /usr/local/bin/install-magento
41+
RUN chmod +x /usr/local/bin/install-magento
42+
43+
COPY ./install-sampledata /usr/local/bin/install-sampledata
44+
RUN chmod +x /usr/local/bin/install-sampledata
45+
46+
RUN a2enmod rewrite
47+
RUN echo "memory_limit=2048M" > /usr/local/etc/php/conf.d/memory-limit.ini
48+
49+
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
50+
51+
WORKDIR $INSTALL_DIR
52+
53+
# Add cron job
54+
ADD crontab /etc/cron.d/magento2-cron
55+
RUN chmod 0644 /etc/cron.d/magento2-cron \
56+
&& crontab -u www-data /etc/cron.d/magento2-cron

README.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,164 @@
55
[![Docker build](http://dockeri.co/image/alexcheng/magento2)](https://hub.docker.com/r/alexcheng/magento2/)
66

77
This repo converts the [long installation guide](http://devdocs.magento.com/guides/v1.0/install-gde/bk-install-guide.html) of Magento 2 into simple Docker image to use. It uses the same convention as my [Docker image for Magento 1.x](https://github.com/alexcheng1982/docker-magento).
8+
9+
For documentation, please refer to the Magento 1.x [repo](https://github.com/alexcheng1982/docker-magento). These two Docker images follow the same instructions.
10+
11+
__Note__ This docker image uses the *Contributing developer* profile to install Magento, so it has limitations. See more details [here](http://devdocs.magento.com/guides/v2.0/install-gde/bk-install-guide.html).
12+
13+
**Please note: this Docker image is for development and testing only, not for production use. Setting up a Magento 2 production server requires more configurations. Please refer to [official documentations](http://devdocs.magento.com/guides/v2.2/config-guide/deployment/).**
14+
15+
## Magento 2 installation types
16+
17+
Magento 2 has three different ways to [install](http://devdocs.magento.com/guides/v2.0/install-gde/bk-install-guide.html), for users, integrators and developers. This Docker image uses **integrator** as the default installation type, so the **Web Setup Wizard** can be used. For each version, both integrator and developer installation types are available. The user installation type is not currently supported.
18+
19+
For example, Magento 2 version `2.2.2` has tag `2.2.2`, `2.2.2-integrator` and `2.2.2-developer`. `2.2.2` is the same as `2.2.2-integrator`.
20+
21+
Below are some basic instructions.
22+
23+
## Quick start
24+
25+
The easiest way to start Magento 2 with MySQL is using [Docker Compose](https://docs.docker.com/compose/). Just clone this repo and run following command in the root directory. The default `docker-compose.yml` uses MySQL and phpMyAdmin.
26+
27+
~~~
28+
$ docker-compose up -d
29+
~~~
30+
31+
For admin username and password, please refer to the file `env`. You can also update the file `env` to update those configurations. Below are the default configurations.
32+
33+
~~~
34+
MYSQL_HOST=db
35+
MYSQL_ROOT_PASSWORD=myrootpassword
36+
MYSQL_USER=magento
37+
MYSQL_PASSWORD=magento
38+
MYSQL_DATABASE=magento
39+
40+
MAGENTO_LANGUAGE=en_GB
41+
MAGENTO_TIMEZONE=Pacific/Auckland
42+
MAGENTO_DEFAULT_CURRENCY=NZD
43+
MAGENTO_URL=http://local.magento
44+
MAGENTO_BACKEND_FRONTNAME=admin
45+
MAGENTO_USE_SECURE=0
46+
MAGENTO_BASE_URL_SECURE=0
47+
MAGENTO_USE_SECURE_ADMIN=0
48+
49+
MAGENTO_ADMIN_FIRSTNAME=Admin
50+
MAGENTO_ADMIN_LASTNAME=MyStore
51+
52+
MAGENTO_ADMIN_USERNAME=admin
53+
MAGENTO_ADMIN_PASSWORD=magentorocks1
54+
~~~
55+
56+
For example, if you want to change the default currency, just update the variable `MAGENTO_DEFAULT_CURRENCY`, e.g. `MAGENTO_DEFAULT_CURRENCY=USD`.
57+
58+
You can find all available options in the official [setup guide](http://devdocs.magento.com/guides/v2.0/install-gde/install/cli/install-cli-install.html#instgde-install-cli-magento). If you need more options, fork this repo and add them in `bin\install-magento`.
59+
60+
Please see the following video for a quick demo.
61+
62+
[![Use Magento 2 with Docker](https://img.youtube.com/vi/18tOf_cuQKg/hqdefault.jpg)](https://www.youtube.com/watch?v=18tOf_cuQKg "Use Magento 2 with Docker")
63+
64+
## Installation
65+
66+
After starting the container, you'll see the setup page of Magento 2. You can use the script `install-magento` to quickly install Magento 2. The installation script uses the variables in the `env` file.
67+
68+
### Magento 2
69+
70+
~~~
71+
$ docker exec -it <container_name> install-magento
72+
~~~
73+
74+
### Sample data
75+
76+
~~~
77+
$ docker exec -it <container_name> install-sampledata
78+
~~~
79+
80+
**Please note:** Sample data for Magento 2.2.2 doesn't work at the moment, see [this issue](https://github.com/alexcheng1982/docker-magento2/issues/11).
81+
82+
### Database
83+
84+
The default `docker-compose.yml` uses MySQL as the database and starts [phpMyAdmin](https://www.phpmyadmin.net/). The default URL for phpMyAdmin is `http://localhost:8580`. Use MySQL username and password to log in.
85+
86+
## FAQ
87+
88+
### Where is the database?
89+
90+
Magento 2 cannot run with a database. This image is for Magento 2 only. It doesn't contain MySQL server. MySQL server should be started in another container and linked with Magento 2 container. It's recommended to use Docker Compose to start both containers. You can also use [Kubernetes](https://kubernetes.io/) or other tools.
91+
92+
### Why accessing http://local.magento?
93+
94+
For development and testing in the local environment, using `localhost` as Magento 2 URL has some issues. The default `env` file use `http://local.magento` as the value of `MAGENTO_URL`. You need to [edit your `hosts` file](https://support.rackspace.com/how-to/modify-your-hosts-file/) to add the mapping from `local.magento` to `localhost`. You can use any domain names as long as it looks like a real domain, not `localhost`.
95+
96+
If `localhost` doesn't work, try using `127.0.0.1`.
97+
98+
```
99+
127.0.0.1 local.magento
100+
```
101+
102+
### How to update Magento 2 installation configurations?
103+
104+
Depends on how the container is used,
105+
106+
* When using the GUI setup page of Magento 2, update configurations in the UI.
107+
* When using the script, update configurations in the `env` file.
108+
* When starting Magento 2 as a standalone container, use `-e` to pass environment variables.
109+
110+
### Why getting access denied error after changing the default DB password?
111+
112+
If you change the default DB password in `env` file and get the access denied error when installing Magento 2, see [this issue comment](https://github.com/alexcheng1982/docker-magento2/issues/10#issuecomment-355382150).
113+
114+
## Develop and test using this Docker image
115+
116+
As I mentioned before, this Docker image is primarily used for development and testing. Depends on the tasks you are trying to do, there are different ways to use this Docker image.
117+
118+
### Extensions and themes
119+
120+
You can keep the extensions and themes directories on your local host machine, and use Docker Compose [volumes](https://docs.docker.com/compose/compose-file/#volumes) to install the extensions and themes. For example, if you have a theme in the directory `/dev/mytheme`, you can install it by specifying it in the `docker-composer.yml` file. Then you can see the theme in Magento admin UI.
121+
122+
```yml
123+
version: '3.0'
124+
services:
125+
web:
126+
image: alexcheng/magento2
127+
ports:
128+
- "80:80"
129+
links:
130+
- db
131+
env_file:
132+
- env
133+
volumes:
134+
- /dev/mytheme:/var/www/html/app/design/frontend/mytheme/default
135+
db:
136+
image: mysql:5.6.23
137+
volumes:
138+
- db-data:/var/lib/mysql/data
139+
env_file:
140+
- env
141+
phpmyadmin:
142+
image: phpmyadmin/phpmyadmin
143+
ports:
144+
- "8580:80"
145+
links:
146+
- db
147+
volumes:
148+
db-data:
149+
```
150+
151+
### Modify Magento core files
152+
153+
If you want to modify Magento core files, you cannot modify them directly in the container. Those changes will be lost. It's also not recommended to update Magento core files directly, which makes upgrading Magento a painful process. Actually, Docker makes the process much easier if you absolutely need to modify some core files. You can use volumes to overwrite files.
154+
155+
For example, if you want to overwrite the file `app/code/Magento/Catalog/Block/Product/Price.php`, you can copy the content to a new file in your local directory `/dev/mycode/magento_2_2` and make the changes, then use `volumes` to overwrite it.
156+
157+
```yml
158+
volumes:
159+
- /dev/mycode/magento_2_2/app/code/Magento/Catalog/Block/Product/Price.php:/var/www/html/app/code/Magento/Catalog/Block/Product/Price.php
160+
```
161+
162+
By using Docker, we can make sure that all your changes to Magento core files are kept in one place and tracked in source code repository. These changes are also correctly aligned with different Magento versions.
163+
164+
When deploying those changes to production servers, we can simply copy all files in the `/dev/mycode/magento_2_2` directory to Magento installation directory and overwrite existing files.
165+
166+
### Test Magento compatibilities
167+
168+
This Docker images has different tags for corresponding Magento versions, e.g. `2.2.1`, `2.2.2`. You can switch to different Magento versions very easily when testing extensions and themes.

bin/install-magento

Lines changed: 0 additions & 7 deletions
This file was deleted.

crontab

Lines changed: 0 additions & 2 deletions
This file was deleted.

crontab.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/var/log/magento.cron.log
2+
* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento indexer:reindex
3+
{{{extraCronJobs}}}

developer/Dockerfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
FROM alexcheng/apache2-php7:7.0.24
2+
3+
LABEL maintainer="[email protected]"
4+
LABEL version="2.0.17"
5+
LABEL description="Magento 2.0.17"
6+
7+
ENV MAGENTO_VERSION 2.0.17
8+
ENV INSTALL_DIR /var/www/html
9+
ENV COMPOSER_HOME /var/www/.composer/
10+
11+
RUN curl -sS https://getcomposer.org/installer | php \
12+
&& mv composer.phar /usr/local/bin/composer
13+
COPY ./auth.json $COMPOSER_HOME
14+
15+
RUN requirements="libpng12-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 libjpeg-turbo8 libjpeg-turbo8-dev libpng12-dev libfreetype6-dev libicu-dev libxslt1-dev" \
16+
&& apt-get update \
17+
&& apt-get install -y $requirements \
18+
&& rm -rf /var/lib/apt/lists/* \
19+
&& docker-php-ext-install pdo_mysql \
20+
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
21+
&& docker-php-ext-install gd \
22+
&& docker-php-ext-install mcrypt \
23+
&& docker-php-ext-install mbstring \
24+
&& docker-php-ext-install zip \
25+
&& docker-php-ext-install intl \
26+
&& docker-php-ext-install xsl \
27+
&& docker-php-ext-install soap \
28+
&& requirementsToRemove="libpng12-dev libmcrypt-dev libcurl3-dev libpng12-dev libfreetype6-dev libjpeg-turbo8-dev" \
29+
&& apt-get purge --auto-remove -y $requirementsToRemove
30+
31+
RUN chsh -s /bin/bash www-data
32+
33+
RUN cd /tmp && \
34+
curl https://codeload.github.com/magento/magento2/tar.gz/$MAGENTO_VERSION -o $MAGENTO_VERSION.tar.gz && \
35+
tar xvf $MAGENTO_VERSION.tar.gz && \
36+
mv magento2-$MAGENTO_VERSION/* magento2-$MAGENTO_VERSION/.htaccess $INSTALL_DIR
37+
38+
RUN chown -R www-data:www-data /var/www
39+
RUN su www-data -c "cd $INSTALL_DIR && composer install"
40+
RUN su www-data -c "cd $INSTALL_DIR && composer config repositories.magento composer https://repo.magento.com/"
41+
42+
RUN cd $INSTALL_DIR \
43+
&& find . -type d -exec chmod 770 {} \; \
44+
&& find . -type f -exec chmod 660 {} \; \
45+
&& chmod u+x bin/magento
46+
47+
COPY ./install-magento /usr/local/bin/install-magento
48+
RUN chmod +x /usr/local/bin/install-magento
49+
50+
COPY ./install-sampledata /usr/local/bin/install-sampledata
51+
RUN chmod +x /usr/local/bin/install-sampledata
52+
53+
RUN a2enmod rewrite
54+
RUN echo "memory_limit=2048M" > /usr/local/etc/php/conf.d/memory-limit.ini
55+
56+
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
57+
58+
WORKDIR $INSTALL_DIR
59+
60+
# Add cron job
61+
ADD crontab /etc/cron.d/magento2-cron
62+
RUN chmod 0644 /etc/cron.d/magento2-cron \
63+
&& crontab -u www-data /etc/cron.d/magento2-cron

developer/auth.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"http-basic": {
3+
"repo.magento.com": {
4+
"username": "5310458a34d580de1700dfe826ff19a1",
5+
"password": "255059b03eb9d30604d5ef52fca7465d"
6+
}
7+
}
8+
}

developer/crontab

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/var/log/magento.cron.log
2+
* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento indexer:reindex
3+

developer/install-magento

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
su www-data <<EOSU
4+
5+
/var/www/html/bin/magento setup:install --base-url=$MAGENTO_URL --backend-frontname=$MAGENTO_BACKEND_FRONTNAME --language=$MAGENTO_LANGUAGE --timezone=$MAGENTO_TIMEZONE --currency=$MAGENTO_DEFAULT_CURRENCY --db-host=$MYSQL_HOST --db-name=$MYSQL_DATABASE --db-user=$MYSQL_USER --db-password=$MYSQL_PASSWORD --use-secure=$MAGENTO_USE_SECURE --base-url-secure=$MAGENTO_BASE_URL_SECURE --use-secure-admin=$MAGENTO_USE_SECURE_ADMIN --admin-firstname=$MAGENTO_ADMIN_FIRSTNAME --admin-lastname=$MAGENTO_ADMIN_LASTNAME --admin-email=$MAGENTO_ADMIN_EMAIL --admin-user=$MAGENTO_ADMIN_USERNAME --admin-password=$MAGENTO_ADMIN_PASSWORD
6+
7+
EOSU

0 commit comments

Comments
 (0)