├── .env ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── bin └── console ├── composer.json ├── config ├── appdata │ └── startup.sh ├── nginx │ ├── auth │ │ └── htpasswd │ ├── nginx.conf │ ├── sites-enabled │ │ └── default.conf │ └── ssl │ │ └── .gitignore └── php │ ├── ext-xdebug.ini │ ├── image │ └── Dockerfile │ ├── php-fpm.conf │ └── php.ini └── docker-compose.yml /.env: -------------------------------------------------------------------------------- 1 | DATABASE_NAME=magento2dockerized 2 | DATABASE_USER=magento 3 | DATABASE_PASSWORD=enAVINa2 4 | DATABASE_ROOT_PASSWORD=enAVINa2 5 | 6 | ADMIN_USERNAME=admin 7 | ADMIN_FIRSTNAME=Admin 8 | ADMIN_LASTNAME=Inistrator 9 | ADMIN_EMAIL=johndoe@example.com 10 | ADMIN_PASSWORD=enAVINa2 11 | 12 | DEFAULT_LANGUAGE=en_US 13 | DEFAULT_CURRENCY=EUR 14 | DEFAULT_TIMEZONE=Europe/Berlin 15 | 16 | BACKEND_FRONTNAME=management 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arvatoSCM/dockerize-magento2/ac8fddf0cdb6e4810a00dc87da84ff2fcba9992c/.gitignore -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be [documented](http://keepachangelog.com/) in this file. 3 | This project adheres to [Semantic Versioning](http://semver.org/). 4 | 5 | ## [v1.2.1] - 2017-01-12 6 | 7 | Fix Nginx handling of versioned assets 8 | 9 | ### Fixed 10 | - Fix the nginx config to support versioned assets 11 | 12 | ## [v1.2.0] - 2017-01-12 13 | 14 | ### Changed 15 | - Replace config/env.sh with a regular Docker Compose .env file 16 | 17 | ### Added 18 | - Add support for versioned assets that have made the default with Magento 2.1.3 (see: [magento/magento2 issue #7820](https://github.com/magento/magento2/issues/7820)) 19 | 20 | ## [v1.1.0] 21 | 22 | ### Added 23 | - Add support for lets encrypt 24 | 25 | ### Changed 26 | - Use the pre-built arvato/magento2-php docker image for a faster setup (see: https://hub.docker.com/r/arvato/magento2-php/) 27 | 28 | ## v1.0.0 29 | ### Added 30 | - Initial version of the Docker Compose control script (bin/console) and required configuration files for Nginx, PHP and MySQL 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2016 arvato distribution GmbH 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dockerize Magento 2 2 | 3 | A composer package for dockerizing Magento 2 4 | 5 | The composer package **arvatoscm/dockerize-magento2** deploys docker infrastructure defintion files such as [docker-compose.yml](docker-compose.yml) to your Magento 2 root folder and enables you to host your Magento 2 shops without having to install Apache/Nginx, MySQL or PHP on your system. 6 | 7 | ## Package Name 8 | 9 | `arvatoscm/dockerize-magento2` 10 | 11 | ## Software Requirements 12 | 13 | For Linux users you must have a recent version of [docker](https://github.com/docker/docker/releases) and [docker-compose](https://github.com/docker/compose/releases) installed. 14 | 15 | If you are a Mac or Windows user, use the [Docker Toolbox](https://www.docker.com/products/docker-toolbox). 16 | 17 | ## Installation 18 | 19 | Add `arvatoscm/dockerize-magento2` to your existing Magento 2 shop: 20 | 21 | ```bash 22 | composer require --ignore-platform-reqs arvatoscm/dockerize-magento2 23 | chmod +x bin/console 24 | ``` 25 | 26 | This will place some files in your Magento root: 27 | 28 | - `docker-compose.yml` 29 | The docker infrastructure definition 30 | - `bin/console` 31 | A utility script for controlling dockerized Magento projects 32 | - `config` 33 | A folder which contains the configuration files for PHP, Nginx and phpMyAdmin 34 | 35 | 36 | ## Usage 37 | 38 | `dockerize-magento2` comes with `bin/console` script that can be used to install Magento and to execute Magentos' bin/magento script inside the PHP docker container: 39 | 40 | Trigger the Magento 2 installation process: 41 | 42 | ```bash 43 | bin/console install 44 | ``` 45 | 46 | Start the docker containers: 47 | 48 | ```bash 49 | bin/console start 50 | ``` 51 | 52 | Stop the docker containers: 53 | 54 | ```bash 55 | bin/console stop 56 | ``` 57 | 58 | Execute `bin/magento` inside the docker container: 59 | 60 | ```bash 61 | bin/console exec [arguments] 62 | ``` 63 | 64 | For more information on how to use docker-compose visit: https://docs.docker.com/compose/ 65 | 66 | ## Configuration 67 | 68 | The `install` action depends on some parameters such as usernames and passwords. We have put in some default values for you that will work for a quick test: 69 | 70 | ``` 71 | DATABASE_NAME="magento2dockerized" 72 | DATABASE_USER="magento" 73 | DATABASE_PASSWORD="enAVINa2" 74 | DATABASE_ROOT_PASSWORD="enAVINa2" 75 | 76 | ADMIN_USERNAME="admin" 77 | ADMIN_FIRSTNAME="Admin" 78 | ADMIN_LASTNAME="Inistrator" 79 | ADMIN_EMAIL="johndoe@example.com" 80 | ADMIN_PASSWORD="enAVINa2" 81 | 82 | DEFAULT_LANGUAGE="en_US" 83 | DEFAULT_CURRENCY="EUR" 84 | DEFAULT_TIMEZONE="Europe/Berlin" 85 | 86 | BACKEND_FRONTNAME="management" 87 | ``` 88 | 89 | If you want to use different parameters change the values in the [.env](.env) file to your needs. 90 | After customizing the parameters just run trigger the installation with `bin/console install `. 91 | 92 | ## Licensing 93 | 94 | dockerize-magento2 is licensed under the Apache License, Version 2.0. 95 | See [LICENSE](LICENSE) for the full license text. 96 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # A proxy script that executes bin/magento inside 4 | # the PHP docker container. 5 | 6 | # SCRIPTNAME contains the name 7 | # of the current script (e.g. "server") 8 | SCRIPTNAME="bin/$(basename $0)" 9 | 10 | # PROJECTPATH contains the full 11 | # directory path of the project itself 12 | PROJECTPATH=$(pwd) 13 | 14 | # CONFIGFOLDER contains the path 15 | # to the config folder. 16 | CONFIGFOLDER="$PROJECTPATH/config" 17 | 18 | # SSLCERTIFICATEFOLDER contains the path 19 | # to the SSL certificate folder that is used by Nginx. 20 | SSLCERTIFICATEFOLDER="$CONFIGFOLDER/nginx/ssl" 21 | 22 | # ENVIRONMENTVARIABLESFILE contains the path 23 | # to the file that holds the required environment 24 | # variables for this script. 25 | ENVIRONMENTVARIABLESFILE="$PROJECTPATH/.env" 26 | if [ ! -f $ENVIRONMENTVARIABLESFILE ]; then 27 | echo >&2 "The file that holds the environment variables was not found at $ENVIRONMENTVARIABLESFILE" 28 | exit 1 29 | fi 30 | 31 | # DOCKERCOMPOSEFILE contains the path 32 | # to the docker-compose.yml file 33 | DOCKERCOMPOSEFILE="$PROJECTPATH/docker-compose.yml" 34 | if [ ! -f $DOCKERCOMPOSEFILE ]; then 35 | echo >&2 "The docker-compose file was not found at $DOCKERCOMPOSEFILE" 36 | exit 1 37 | fi 38 | 39 | # execute the file that sets the environment variables 40 | . $ENVIRONMENTVARIABLESFILE 41 | 42 | # check the environment variables 43 | if [ -z "$DATABASE_NAME" ]; then 44 | echo >&2 "The DATABASE_NAME variable is not set" 45 | exit 1 46 | fi 47 | 48 | if [ -z "$DATABASE_USER" ]; then 49 | echo >&2 "The DATABASE_USER variable is not set" 50 | exit 1 51 | fi 52 | 53 | if [ -z "$DATABASE_PASSWORD" ]; then 54 | echo >&2 "The DATABASE_PASSWORD variable is not set" 55 | exit 1 56 | fi 57 | 58 | if [ -z "$DATABASE_ROOT_PASSWORD" ]; then 59 | echo >&2 "The DATABASE_ROOT_PASSWORD variable is not set" 60 | exit 1 61 | fi 62 | 63 | if [ -z "$ADMIN_USERNAME" ]; then 64 | echo >&2 "The ADMIN_USERNAME variable is not set" 65 | exit 1 66 | fi 67 | 68 | if [ -z "$ADMIN_FIRSTNAME" ]; then 69 | echo >&2 "The ADMIN_FIRSTNAME variable is not set" 70 | exit 1 71 | fi 72 | 73 | if [ -z "$ADMIN_LASTNAME" ]; then 74 | echo >&2 "The ADMIN_LASTNAME variable is not set" 75 | exit 1 76 | fi 77 | 78 | if [ -z "$ADMIN_EMAIL" ]; then 79 | echo >&2 "The ADMIN_EMAIL variable is not set" 80 | exit 1 81 | fi 82 | 83 | if [ -z "$ADMIN_PASSWORD" ]; then 84 | echo >&2 "The ADMIN_PASSWORD variable is not set" 85 | exit 1 86 | fi 87 | 88 | if [ -z "$DEFAULT_LANGUAGE" ]; then 89 | echo >&2 "The DEFAULT_LANGUAGE variable is not set" 90 | exit 1 91 | fi 92 | 93 | if [ -z "$DEFAULT_CURRENCY" ]; then 94 | echo >&2 "The DEFAULT_CURRENCY variable is not set" 95 | exit 1 96 | fi 97 | 98 | if [ -z "$DEFAULT_TIMEZONE" ]; then 99 | echo >&2 "The DEFAULT_TIMEZONE variable is not set" 100 | exit 1 101 | fi 102 | 103 | if [ -z "$BACKEND_FRONTNAME" ]; then 104 | echo >&2 "The BACKEND_FRONTNAME variable is not set" 105 | exit 1 106 | fi 107 | 108 | 109 | # Check availability of docker 110 | hash docker 2>/dev/null || { echo >&2 "$SCRIPTNAME requires \"docker\""; exit 1; } 111 | 112 | # Check availability of docker-compose 113 | hash docker-compose 2>/dev/null || { echo >&2 "$SCRIPTNAME requires \"docker-compose\""; exit 1; } 114 | 115 | 116 | ####################################### 117 | # Execute bin/magento inside the php docker 118 | # container with all given arguments. 119 | # Globals: 120 | # None 121 | # Arguments: 122 | # * 123 | # Returns: 124 | # None 125 | ####################################### 126 | executeInDocker() { 127 | 128 | if [ $(isRunning) = false ]; then 129 | echo >&2 "Docker is not running. Please start the containers first."; 130 | exit 1; 131 | fi 132 | 133 | # pass the arguments to the bin/magento script inside the PHP container 134 | docker-compose exec php bash -c "bin/magento $*" 135 | } 136 | 137 | ####################################### 138 | # Generate new SSL certificates 139 | # Globals: 140 | # SSLKEYFILEPATH 141 | 142 | # Arguments: 143 | # hostname 144 | # Returns: 145 | # None 146 | ####################################### 147 | generateSSLCertificate() { 148 | # abort if no hostname was specified 149 | hostname=$1 150 | if [ -z "$hostname" ]; then 151 | echo >&2 "No hostname given" 152 | return 1 153 | fi 154 | 155 | # assemble file paths for key and cert 156 | SSLKEYFILEPATH="$SSLCERTIFICATEFOLDER/key.pem" 157 | SSLCERTFILEPATH="$SSLCERTIFICATEFOLDER/cert.pem" 158 | 159 | # check if the certificates already exist 160 | if [ -f "$SSLKEYFILEPATH" ] && [ -f "$SSLCERTFILEPATH" ] 161 | then 162 | echo "Using existing SSL certificates:" 163 | printf " %-8s%-30s\n" "Key:" $SSLKEYFILEPATH 164 | printf " %-8s%-30s\n" "Cert:" $SSLCERTFILEPATH 165 | return 0 166 | fi 167 | 168 | # Check availability of openssl 169 | hash openssl 2>/dev/null || { 170 | echo >&2 "$SCRIPTNAME requires \"openssl\" to generate SSL certificates." 171 | echo >&2 "Please install openssl or place the SSL certificate and key manually into the certificate-folder \"$SSLCERTIFICATEFOLDER\":" 172 | printf >&2 " %-8s%-30s\n" "Key:" $SSLKEYFILEPATH 173 | printf >&2 " %-8s%-30s\n" "Cert:" $SSLCERTFILEPATH 174 | return 1 175 | } 176 | 177 | openssl req -x509 -newkey rsa:2048 -nodes -subj "/CN=$hostname" -keyout $SSLKEYFILEPATH -out $SSLCERTFILEPATH -days 360 2>/dev/null 178 | if [ $? -ne 0 ]; then 179 | echo >&2 "Generating SSL certificates failed." 180 | echo >&2 "Please place the key and certificate into the certificate-folder \"$SSLCERTIFICATEFOLDER\":" 181 | printf >&2 " %-8s%-30s\n" "Key:" $SSLKEYFILEPATH 182 | printf >&2 " %-8s%-30s\n" "Cert:" $SSLCERTFILEPATH 183 | 184 | return 1 185 | fi 186 | 187 | echo "Generated new SSL certificates for $hostname:" 188 | printf " %-8s%-30s\n" "Key:" $SSLKEYFILEPATH 189 | printf " %-8s%-30s\n" "Cert:" $SSLCERTFILEPATH 190 | return 0 191 | } 192 | 193 | ####################################### 194 | # Install Magento 195 | # Globals: 196 | # DATABASE_NAME 197 | # DATABASE_USER 198 | # DATABASE_PASSWORD 199 | # ADMIN_USERNAME 200 | # ADMIN_FIRSTNAME 201 | # ADMIN_LASTNAME 202 | # ADMIN_EMAIL 203 | # ADMIN_PASSWORD 204 | # DEFAULT_LANGUAGE 205 | # DEFAULT_CURRENCY 206 | # DEFAULT_TIMEZONE 207 | # BACKEND_FRONTNAME 208 | # Arguments: 209 | # hostname 210 | # Returns: 211 | # None 212 | ####################################### 213 | installMagento() { 214 | 215 | # get the hostname from the arguments 216 | hostname=$1 217 | if [ -z "$hostname" ]; then 218 | echo >&2 "Please specify a hostname for your Magento shop (e.g. \"www.example.com\")\n" 219 | echo >&2 "Usage:\n" 220 | echo >&2 " $SCRIPTNAME install www.example.com" 221 | 222 | exit 1 223 | fi 224 | 225 | # generate a SSL certificate 226 | generateSSLCertificate $hostname 227 | if [ $? -ne 0 ]; then 228 | exit 1 229 | fi 230 | 231 | # Add write permissions for pub folder 232 | chmod -R g+w pub 233 | 234 | # Start docker containers (docker-compose > v1.6 and docker > v1.10 required) 235 | restart 236 | 237 | # Delete config before install 238 | rm -f app/etc/env.php 239 | 240 | # wait for MySQL to come up 241 | sleep 30 242 | 243 | # Install magento 2 244 | baseURLInsecure="http://${hostname}/" 245 | baseURLSecure="https://${hostname}/" 246 | backendURL="https://${hostname}/${BACKEND_FRONTNAME}" 247 | executeInDocker setup:install --base-url=$baseURLInsecure --base-url-secure=$baseURLSecure --backend-frontname=${BACKEND_FRONTNAME} \ 248 | --language=${DEFAULT_LANGUAGE} --currency=${DEFAULT_CURRENCY} --timezone=${DEFAULT_TIMEZONE} \ 249 | --db-host=mysql --db-name=${DATABASE_NAME} --db-user=${DATABASE_USER} --db-password=${DATABASE_PASSWORD} \ 250 | --admin-firstname=${ADMIN_FIRSTNAME} --admin-lastname=${ADMIN_LASTNAME} --admin-email=${ADMIN_EMAIL} --admin-user=${ADMIN_USERNAME} --admin-password=${ADMIN_PASSWORD} \ 251 | --cleanup-database --session-save=db 252 | 253 | # Install and update modules 254 | executeInDocker setup:upgrade 255 | 256 | # Clear cache 257 | executeInDocker cache:clean 258 | 259 | # Index data 260 | executeInDocker indexer:reindex 261 | 262 | # Print results 263 | echo "\n" 264 | echo "Installation complete.\n" 265 | 266 | printf "%-15s%-30s\n" "Frontend" $baseURLInsecure 267 | printf "%-15s%-30s\n" "Backend" $backendURL 268 | printf "%-15s%s: %s\n" "" "Username" ${ADMIN_USERNAME} 269 | printf "%-15s%s: %s\n" "" "Password" ${ADMIN_PASSWORD} 270 | 271 | } 272 | 273 | ####################################### 274 | # Print the status of the server 275 | # Globals: 276 | # None 277 | # Arguments: 278 | # None 279 | # Returns: 280 | # None 281 | ####################################### 282 | status() { 283 | if [ $(isRunning) = false ]; then 284 | echo >&2 "Not running"; 285 | exit 1; 286 | fi 287 | 288 | # docker status 289 | docker-compose -f $DOCKERCOMPOSEFILE ps -q | xargs docker inspect --format='{{ .Name }} {{ .State.Status }}' | sed 's:^/::g' | xargs printf "%-45s%-30s\n" 290 | 291 | } 292 | 293 | ####################################### 294 | # Stop the server 295 | # Globals: 296 | # None 297 | # Arguments: 298 | # None 299 | # Returns: 300 | # None 301 | ####################################### 302 | stop() { 303 | 304 | if [ $(isRunning) = true ]; then 305 | # stop all docker containers 306 | docker-compose -f $DOCKERCOMPOSEFILE down 307 | fi 308 | 309 | } 310 | 311 | ####################################### 312 | # Start the server and all of its 313 | # components 314 | # Globals: 315 | # None 316 | # Arguments: 317 | # None 318 | # Returns: 319 | # None 320 | ####################################### 321 | start() { 322 | 323 | if [ $(isRunning) = true ]; then 324 | echo >&2 "The component are already running"; 325 | exit 1; 326 | fi 327 | 328 | # start docker containers 329 | docker-compose -f $DOCKERCOMPOSEFILE up -d 330 | 331 | } 332 | 333 | ####################################### 334 | # Restart the server and all of its 335 | # components 336 | # Globals: 337 | # None 338 | # Arguments: 339 | # None 340 | # Returns: 341 | # None 342 | ####################################### 343 | restart() { 344 | stop 345 | start 346 | } 347 | 348 | ####################################### 349 | # Check if the docker-components are running 350 | # Globals: 351 | # DOCKERCOMPOSEFILE 352 | # Arguments: 353 | # None 354 | # Returns: 355 | # true|false 356 | ####################################### 357 | isRunning() { 358 | dockerStatusOutput=$(docker-compose -f $DOCKERCOMPOSEFILE ps -q) 359 | outputSize=${#dockerStatusOutput} 360 | if [ "$outputSize" -gt 0 ]; then 361 | echo true 362 | else 363 | echo false 364 | fi 365 | } 366 | 367 | ####################################### 368 | # Print the usage information for the 369 | # server control script 370 | # Globals: 371 | # SCRIPTNAME 372 | # Arguments: 373 | # None 374 | # Returns: 375 | # None 376 | ####################################### 377 | usage() { 378 | echo "Utility for controlling dockerized Magento projects\n" 379 | echo "Usage:\n\n $SCRIPTNAME " 380 | echo "" 381 | echo "Actions:\n" 382 | printf " %-15s%-30s\n" "install" "Install Magento" 383 | printf " %-15s%-30s\n" "exec" "Execute bin/magento inside docker" 384 | echo "" 385 | printf " %-15s%-30s\n" "start" "Start the server and all of its components" 386 | printf " %-15s%-30s\n" "restart" "Restart the server" 387 | printf " %-15s%-30s\n" "stop" "Stop the server" 388 | printf " %-15s%-30s\n" "status" "Get the current server status" 389 | } 390 | 391 | case "$1" in 392 | install) 393 | shift 1 394 | installMagento $* 395 | ;; 396 | 397 | exec) 398 | shift 1 399 | executeInDocker $* 400 | ;; 401 | 402 | start) 403 | start 404 | ;; 405 | 406 | restart) 407 | restart 408 | ;; 409 | 410 | stop) 411 | stop 412 | ;; 413 | 414 | status) 415 | status 416 | ;; 417 | 418 | *) 419 | usage 420 | ;; 421 | esac 422 | 423 | exit 0 424 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "arvatoscm/dockerize-magento2", 3 | "description": "Docker infrastructure definitions for Magento 2", 4 | "license": "Apache-2.0", 5 | "authors": [ 6 | { 7 | "name": "Andreas Koch", 8 | "email": "andy@ak7.io", 9 | "homepage": "https://github.com/andreaskoch", 10 | "role": "Author" 11 | } 12 | ], 13 | "type": "magento2-component", 14 | "homepage": "https://github.com/arvatoSCM/dockerize-magento2", 15 | "extra": { 16 | "map": [ 17 | [ 18 | "docker-compose.yml", 19 | "docker-compose.yml" 20 | ], 21 | [ 22 | "config", 23 | "config" 24 | ], 25 | [ 26 | ".env", 27 | ".env" 28 | ], 29 | [ 30 | "bin/console", 31 | "bin/console" 32 | ] 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /config/appdata/startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Set the correct file permissions for Magento 2 4 | 5 | while true; 6 | do 7 | chgrp -R 33 /var/www 8 | chmod -R g+rs /var/www 9 | 10 | chmod -R ug+rws /var/www/html/pub/errors 11 | chmod -R ug+rws /var/www/html/pub/static 12 | chmod -R ug+rws /var/www/html/pub/media 13 | chmod -R ug+rws /var/www/html/app/etc 14 | chmod -R ug+rws /var/www/html/var 15 | 16 | chmod ug+x /var/www/html/bin/magento 17 | 18 | sleep 60 19 | done 20 | -------------------------------------------------------------------------------- /config/nginx/auth/htpasswd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arvatoSCM/dockerize-magento2/ac8fddf0cdb6e4810a00dc87da84ff2fcba9992c/config/nginx/auth/htpasswd -------------------------------------------------------------------------------- /config/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | user www-data; 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 | '$request_time'; 17 | 18 | access_log /dev/stdout main; 19 | error_log /dev/stderr warn; 20 | 21 | sendfile on; 22 | keepalive_timeout 65; 23 | 24 | server_tokens off; 25 | 26 | include /etc/nginx/sites-enabled/*; 27 | } 28 | -------------------------------------------------------------------------------- /config/nginx/sites-enabled/default.conf: -------------------------------------------------------------------------------- 1 | upstream fastcgi_backend { 2 | server php:9000; 3 | } 4 | 5 | server { 6 | listen 80 default_server; 7 | listen 443 default_server ssl; 8 | 9 | ssl_certificate /etc/nginx/ssl/cert.pem; 10 | ssl_certificate_key /etc/nginx/ssl/key.pem; 11 | 12 | client_max_body_size 10M; 13 | 14 | set $MAGE_ROOT /var/www/html; 15 | set $MAGE_MODE developer; 16 | 17 | root $MAGE_ROOT/pub; 18 | 19 | index index.php; 20 | autoindex off; 21 | charset UTF-8; 22 | error_page 404 403 = /errors/404.php; 23 | 24 | # PHP entry point for setup application 25 | location ~* ^/setup($|/) { 26 | root $MAGE_ROOT; 27 | location ~ ^/setup/index.php { 28 | fastcgi_pass fastcgi_backend; 29 | fastcgi_index index.php; 30 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 31 | include fastcgi_params; 32 | } 33 | 34 | location ~ ^/setup/(?!pub/). { 35 | deny all; 36 | } 37 | 38 | location ~ ^/setup/pub/ { 39 | add_header X-Frame-Options "SAMEORIGIN"; 40 | } 41 | } 42 | 43 | # PHP entry point for update application 44 | location ~* ^/update($|/) { 45 | root $MAGE_ROOT; 46 | 47 | location ~ ^/update/index.php { 48 | fastcgi_split_path_info ^(/update/index.php)(/.+)$; 49 | fastcgi_pass fastcgi_backend; 50 | fastcgi_index index.php; 51 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 52 | fastcgi_param PATH_INFO $fastcgi_path_info; 53 | include fastcgi_params; 54 | } 55 | 56 | # Deny everything but index.php 57 | location ~ ^/update/(?!pub/). { 58 | deny all; 59 | } 60 | 61 | location ~ ^/update/pub/ { 62 | add_header X-Frame-Options "SAMEORIGIN"; 63 | } 64 | } 65 | 66 | location / { 67 | try_files $uri $uri/ /index.php?$args; 68 | } 69 | 70 | location /pub/ { 71 | location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) { 72 | deny all; 73 | } 74 | alias $MAGE_ROOT/pub/; 75 | add_header X-Frame-Options "SAMEORIGIN"; 76 | } 77 | 78 | location /static/ { 79 | # Uncomment the following line in production mode 80 | # expires max; 81 | 82 | # Remove signature of the static files that is used to overcome the browser cache 83 | location ~ ^/static/version { 84 | rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last; 85 | } 86 | 87 | location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ { 88 | add_header Cache-Control "public"; 89 | add_header X-Frame-Options "SAMEORIGIN"; 90 | expires +1y; 91 | 92 | if (!-f $request_filename) { 93 | rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last; 94 | } 95 | } 96 | location ~* \.(zip|gz|gzip|bz2|csv|xml)$ { 97 | add_header Cache-Control "no-store"; 98 | add_header X-Frame-Options "SAMEORIGIN"; 99 | expires off; 100 | 101 | if (!-f $request_filename) { 102 | rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last; 103 | } 104 | } 105 | if (!-f $request_filename) { 106 | rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last; 107 | } 108 | add_header X-Frame-Options "SAMEORIGIN"; 109 | } 110 | 111 | location /media/ { 112 | try_files $uri $uri/ /get.php?$args; 113 | 114 | location ~ ^/media/theme_customization/.*\.xml { 115 | deny all; 116 | } 117 | 118 | location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ { 119 | add_header Cache-Control "public"; 120 | add_header X-Frame-Options "SAMEORIGIN"; 121 | expires +1y; 122 | try_files $uri $uri/ /get.php?$args; 123 | } 124 | location ~* \.(zip|gz|gzip|bz2|csv|xml)$ { 125 | add_header Cache-Control "no-store"; 126 | add_header X-Frame-Options "SAMEORIGIN"; 127 | expires off; 128 | try_files $uri $uri/ /get.php?$args; 129 | } 130 | add_header X-Frame-Options "SAMEORIGIN"; 131 | } 132 | 133 | location /media/customer/ { 134 | deny all; 135 | } 136 | 137 | location /media/downloadable/ { 138 | deny all; 139 | } 140 | 141 | location /media/import/ { 142 | deny all; 143 | } 144 | 145 | # PHP entry point for main application 146 | location ~ (index|get|static|report|404|503)\.php$ { 147 | try_files $uri =404; 148 | fastcgi_pass fastcgi_backend; 149 | fastcgi_buffers 1024 4k; 150 | 151 | fastcgi_read_timeout 600s; 152 | fastcgi_connect_timeout 600s; 153 | 154 | fastcgi_index index.php; 155 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 156 | include fastcgi_params; 157 | } 158 | 159 | gzip on; 160 | gzip_disable "msie6"; 161 | 162 | gzip_comp_level 6; 163 | gzip_min_length 1100; 164 | gzip_buffers 16 8k; 165 | gzip_proxied any; 166 | gzip_types 167 | text/plain 168 | text/css 169 | text/js 170 | text/xml 171 | text/javascript 172 | application/javascript 173 | application/x-javascript 174 | application/json 175 | application/xml 176 | application/xml+rss 177 | image/svg+xml; 178 | gzip_vary on; 179 | 180 | # Banned locations (only reached if the earlier PHP entry point regexes don't match) 181 | location ~* (\.php$|\.htaccess$|\.git) { 182 | deny all; 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /config/nginx/ssl/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /config/php/ext-xdebug.ini: -------------------------------------------------------------------------------- 1 | zend_extension="/usr/lib/php7/xdebug.so" 2 | xdebug.remote_enable=1 3 | xdebug.remote_port=9000 4 | xdebug.overload_var_dump=1 5 | xdebug.default_enable=1 6 | xdebug.remote_connect_back=1 7 | -------------------------------------------------------------------------------- /config/php/image/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.0-fpm 2 | 3 | ENV PHP_EXTRA_CONFIGURE_ARGS --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --enable-intl --enable-opcache --enable-zip 4 | 5 | RUN apt-get update 6 | 7 | RUN \ 8 | apt-get install -y \ 9 | libcurl4-gnutls-dev \ 10 | libxml2-dev \ 11 | libssl-dev 12 | 13 | RUN \ 14 | /usr/local/bin/docker-php-ext-install \ 15 | dom \ 16 | pcntl \ 17 | phar \ 18 | posix 19 | 20 | # Configure PHP 21 | # php module build deps 22 | RUN \ 23 | apt-get install -y \ 24 | g++ \ 25 | autoconf \ 26 | libbz2-dev \ 27 | libltdl-dev \ 28 | libpng12-dev \ 29 | libjpeg62-turbo-dev \ 30 | libfreetype6-dev \ 31 | libxpm-dev \ 32 | libimlib2-dev \ 33 | libicu-dev \ 34 | libmcrypt-dev \ 35 | libxslt1-dev \ 36 | 37 | re2c \ 38 | libpng++-dev \ 39 | libpng3 \ 40 | libvpx-dev \ 41 | zlib1g-dev \ 42 | libgd-dev \ 43 | libtidy-dev \ 44 | libmagic-dev \ 45 | libexif-dev \ 46 | file \ 47 | libssh2-1-dev \ 48 | libjpeg-dev \ 49 | git \ 50 | curl \ 51 | wget \ 52 | librabbitmq-dev \ 53 | libzip-dev \ 54 | libzip2 55 | 56 | # http://devdocs.magento.com/guides/v2.0/install-gde/system-requirements.html 57 | RUN \ 58 | /usr/local/bin/docker-php-ext-install \ 59 | pdo \ 60 | sockets \ 61 | pdo_mysql \ 62 | mysqli \ 63 | mbstring \ 64 | mcrypt \ 65 | hash \ 66 | simplexml \ 67 | xsl \ 68 | soap \ 69 | intl \ 70 | bcmath \ 71 | json \ 72 | opcache \ 73 | zip 74 | 75 | # Make sure the volume mount point is empty 76 | RUN rm -rf /var/www/html/* 77 | 78 | # Set www-data as owner for /var/www 79 | RUN chown -R www-data:www-data /var/www/ 80 | RUN chmod -R g+w /var/www/ 81 | 82 | # Create log folders 83 | RUN mkdir /var/log/php-fpm && \ 84 | touch /var/log/php-fpm/access.log && \ 85 | touch /var/log/php-fpm/error.log && \ 86 | chown -R www-data:www-data /var/log/php-fpm 87 | 88 | RUN docker-php-ext-configure gd --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr \ 89 | && docker-php-ext-install gd 90 | 91 | # Install xdebug 92 | RUN cd /tmp/ && git clone https://github.com/xdebug/xdebug.git \ 93 | && cd xdebug && phpize && ./configure --enable-xdebug && make \ 94 | && mkdir /usr/lib/php7/ && cp modules/xdebug.so /usr/lib/php7/xdebug.so \ 95 | && touch /usr/local/etc/php/ext-xdebug.ini \ 96 | && rm -r /tmp/xdebug \ 97 | && apt-get purge -y --auto-remove 98 | -------------------------------------------------------------------------------- /config/php/php-fpm.conf: -------------------------------------------------------------------------------- 1 | [global] 2 | 3 | error_log = /dev/stderr 4 | log_level = warning 5 | daemonize = no 6 | 7 | [www] 8 | 9 | ; if we send this to /proc/self/fd/1, it never appears 10 | access.log = /dev/stdout 11 | 12 | user = www-data 13 | group = www-data 14 | 15 | listen = [::]:9000 16 | 17 | pm = dynamic 18 | pm.max_children = 5 19 | pm.start_servers = 2 20 | pm.min_spare_servers = 1 21 | pm.max_spare_servers = 3 22 | 23 | pm.status_path = /fpm_status 24 | ping.path = /ping 25 | ping.response = pong 26 | -------------------------------------------------------------------------------- /config/php/php.ini: -------------------------------------------------------------------------------- 1 | [PHP] 2 | 3 | ;;;;;;;;;;;;;;;;;;; 4 | ; Resource Limits ; 5 | ;;;;;;;;;;;;;;;;;;; 6 | 7 | max_execution_time = 18000 8 | max_input_time = 60 9 | memory_limit = 512M 10 | upload_max_filesize = 32M 11 | 12 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 13 | ; Error handling and logging ; 14 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 15 | 16 | error_reporting = E_ALL & ~E_NOTICE | E_DEPRECATED 17 | display_errors = Off 18 | display_startup_errors = Off 19 | log_errors = On 20 | log_errors_max_len = 1024 21 | ignore_repeated_errors = Off 22 | ignore_repeated_source = Off 23 | report_memleaks = On 24 | track_errors = Off 25 | html_errors = On 26 | 27 | date.timezone = "UTC" 28 | 29 | ; disable automatic session start 30 | ; before autoload was initialized 31 | flag session.auto_start = off 32 | 33 | ; enable resulting html compression 34 | zlib.output_compression = on 35 | 36 | ; disable user agent verification to not break multiple image upload 37 | suhosin.session.cryptua = off 38 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | web: 4 | image: nginx:latest 5 | ports: 6 | - "80:80" 7 | - "443:443" 8 | volumes: 9 | - ./config/nginx/sites-enabled/default.conf:/etc/nginx/sites-enabled/default.conf 10 | - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf 11 | - ./config/nginx/ssl:/etc/nginx/ssl 12 | - ./config/nginx/auth:/etc/nginx/auth 13 | volumes_from: 14 | - appdata:ro 15 | depends_on: 16 | - php 17 | networks: 18 | - front 19 | - back 20 | 21 | 22 | php: 23 | image: arvato/magento2-php:latest 24 | volumes: 25 | - ./config/php/php.ini:/usr/local/etc/php/php.ini 26 | - ./config/php/php-fpm.conf:/usr/local/etc/php-fpm.conf 27 | - ./config/php/ext-xdebug.ini:/usr/local/etc/php/conf.d/ext-xdebug.ini 28 | volumes_from: 29 | - appdata 30 | env_file: .env 31 | depends_on: 32 | - appdata 33 | - mysql 34 | - cache 35 | user: www-data 36 | networks: 37 | - back 38 | 39 | 40 | appdata: 41 | image: alpine:latest 42 | volumes: 43 | - ./config/appdata/startup.sh:/startup.sh 44 | - .:/var/www/html 45 | command: /bin/sh /startup.sh 46 | 47 | 48 | mysql: 49 | image: mysql:5.7 50 | env_file: .env 51 | environment: 52 | MYSQL_ROOT_PASSWORD: ${DATABASE_ROOT_PASSWORD} 53 | MYSQL_DATABASE: ${DATABASE_NAME} 54 | MYSQL_USER: ${DATABASE_USER} 55 | MYSQL_PASSWORD: ${DATABASE_PASSWORD} 56 | volumes: 57 | - magento2mysqldata:/var/lib/mysql 58 | networks: 59 | - back 60 | 61 | 62 | cache: 63 | image: redis:latest 64 | networks: 65 | - back 66 | 67 | phpmyadmin: 68 | image: phpmyadmin/phpmyadmin 69 | ports: 70 | - "8080:80" 71 | environment: 72 | PMA_HOST: "mysql" 73 | PMA_PORT: 3306 74 | networks: 75 | - front 76 | - back 77 | 78 | volumes: 79 | magento2mysqldata: 80 | driver: local 81 | 82 | networks: 83 | front: 84 | driver: bridge 85 | back: 86 | driver: bridge 87 | --------------------------------------------------------------------------------