├── README.md ├── docker-compose.yml └── m2docker ├── Dockerfile └── files ├── config ├── 20-mcrypt.ini ├── apache_default_vhost └── my.cnf └── scripts ├── install-magento2.sh └── runserver.sh /README.md: -------------------------------------------------------------------------------- 1 | # Magento 2 Docker - Simple 2 | 3 | This is a local Magento 2 docker build. Nothing fancy, does what it says on the tin. 4 | 5 | I've not pushed it anywhere yet, use at your own risk. 6 | 7 | ## Kudos and Respect 8 | 9 | In order to produce this docker repo for Magento 2 I borrowed heavily from both Alan Kent and Mark Shust. 10 | 11 | I wish I could say it was all my own work, I can't, these trialblazers were ahead of me. Many thanks to both and total kudos. 12 | 13 | - [https://github.com/alankent/docker-magento2-demo-apache](http://) 14 | - [http://mageinferno.com/blog/magento-2-development-docker-os-x](http://) 15 | 16 | You might ask why I did my own version. Well I found Alan's to be a little out of date, but I liked the use of Apache as I'm used to that. I would have forked but it started to move quite a bit away from his. 17 | 18 | Mark's was just a bit away from where I am. I wanted to keep it simple, not use dinghy as I don't have Homebrew, and just well shrink things down a bit. 19 | 20 | # Manual Changes 21 | 22 | If you want to change the release number then do so in `m2docker/files/scripts/install-magento2`, its currently at `2.0.0rc1` and will be updated on next major tag 23 | 24 | # Pre-Requisites 25 | 26 | 1. Install Docker (I'm on OSX) 27 | 2. Install Docker Compose 28 | 3. Open Docker via Applications->Docker->Terminal 29 | 4. Add docker ip address alias to /etc/hosts e.g. 192.168.99.100 docker.localhost.com 30 | 31 | # Execution 32 | 33 | 1. git clone this 34 | 2. In base directory do `docker-compose build` 35 | 3. Go have a cup of tea 36 | 4. When finished do `docker-compose up` 37 | 5. Connect to magento in browser via your docker ip address (you see this when you first load docker terminal window) 38 | 39 | 40 | # Useful Docker commands 41 | 42 | docker ps 43 | 44 | docker images 45 | 46 | docker exec -it bash 47 | 48 | docker stop 49 | 50 | 51 | # Notes 52 | 53 | There is no sample data, I'm not a fan. 54 | 55 | It's simple. 56 | 57 | Not intended in anyway for Production use. 58 | 59 | 60 | #TODOs 61 | 62 | Maybe some compilation on frontend to speed it up 63 | 64 | Mount the volumes so we can use as a local development environment 65 | 66 | 67 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | mysql: 2 | image: mysql:5.6 3 | ports: 4 | - "3306:3306" 5 | environment: 6 | - MYSQL_ROOT_PASSWORD=admin 7 | app: 8 | build: m2docker 9 | ports: 10 | - "80:80" 11 | links: 12 | - mysql 13 | environment: 14 | - MYSQL_USER=root 15 | - MYSQL_PASSWORD=admin 16 | - PUBLIC_HOST=docker.localhost.com 17 | -------------------------------------------------------------------------------- /m2docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:trusty 2 | MAINTAINER Karen Baker 3 | 4 | RUN echo "Heavily copied from Alan Kent - https://github.com/alankent/docker-magento2-demo-apache" 5 | 6 | # Get Apache, mysql client, PHP etc (subset of a full LAMP stack - no MySQL server) 7 | RUN apt-get update && apt-get install -y apache2 mysql-client php5 php5-curl php5-mcrypt php5-gd php5-mysql php5-intl curl git php5-xsl 8 | 9 | # mcrypt.ini appears to be missing from apt-get install. Needed for PHP mcrypt library to be enabled. 10 | ADD files/config/20-mcrypt.ini /etc/php5/cli/conf.d/20-mcrypt.ini 11 | ADD files/config/20-mcrypt.ini /etc/php5/apache2/conf.d/20-mcrypt.ini 12 | 13 | # Environment variables from /etc/apache2/apache2.conf 14 | ENV APACHE_RUN_USER www-data 15 | ENV APACHE_RUN_GROUP www-data 16 | ENV APACHE_RUN_DIR /var/run/apache2 17 | ENV APACHE_LOG_DIR /var/log/apache2 18 | ENV APACHE_LOCK_DIR /var/lock/apache2 19 | ENV APACHE_PID_FILE /var/run/apache2/apache2.pid 20 | 21 | # Enable Apache rewrite module 22 | RUN a2enmod rewrite 23 | 24 | # Add the Apache virtual host file 25 | ADD files/config/apache_default_vhost /etc/apache2/sites-enabled/magento2.conf 26 | RUN rm -f /etc/apache2/sites-enabled/000-default.conf 27 | 28 | # Add the MySQL client configuration file (no server settings) 29 | ADD files/config/my.cnf /etc/mysql/my.cnf 30 | 31 | # Install Magento 2 32 | RUN mkdir /var/www/magento2 33 | ADD files/scripts/install-magento2.sh /var/www/install-magento2.sh 34 | RUN bash -x /var/www/install-magento2.sh 35 | 36 | # Expose the web server port 37 | EXPOSE 80 38 | 39 | # Start up the Apache server 40 | ADD files/scripts/runserver.sh /usr/local/bin/runserver.sh 41 | RUN chmod +x /usr/local/bin/runserver.sh 42 | ENTRYPOINT ["bash", "-c"] 43 | CMD ["/usr/local/bin/runserver.sh"] 44 | -------------------------------------------------------------------------------- /m2docker/files/config/20-mcrypt.ini: -------------------------------------------------------------------------------- 1 | ; configuration for php mcrypt module 2 | ; priority=20 3 | extension=mcrypt.so 4 | -------------------------------------------------------------------------------- /m2docker/files/config/apache_default_vhost: -------------------------------------------------------------------------------- 1 | 2 | 3 | DocumentRoot /var/www/magento2/htdocs 4 | 5 | 6 | Options Indexes FollowSymLinks 7 | AllowOverride All 8 | Order allow,deny 9 | allow from all 10 | 11 | 12 | ErrorLog ${APACHE_LOG_DIR}/error.log 13 | LogLevel warn 14 | CustomLog ${APACHE_LOG_DIR}/access.log combined 15 | 16 | 17 | -------------------------------------------------------------------------------- /m2docker/files/config/my.cnf: -------------------------------------------------------------------------------- 1 | # MySQL Client configuration (only) 2 | 3 | [client] 4 | port = 3306 5 | host = mysql 6 | -------------------------------------------------------------------------------- /m2docker/files/scripts/install-magento2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # See also http://alankent.wordpress.com/2014/08/02/magento-2-progress-towards-installation-via-composer/ 4 | 5 | cd /var/www/magento2 6 | 7 | rm -rf htdocs 8 | 9 | curl -sS https://getcomposer.org/installer | php 10 | php composer.phar create-project magento/project-community-edition htdocs 2.0.0-rc --prefer-dist 11 | 12 | # Swap to developer mode for better error diagnostics 13 | #echo "SetEnv MAGE_MODE production" >> .htaccess 14 | echo "SetEnv MAGE_MODE developer" >> htdocs/.htaccess 15 | 16 | chown www-data:www-data -R /var/www/magento2 17 | cd htdocs 18 | find . -type d -exec chmod 770 {} \; && find . -type f -exec chmod 660 {} \; && chmod u+x bin/magento 19 | -------------------------------------------------------------------------------- /m2docker/files/scripts/runserver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Show what we execute 4 | set -x 5 | 6 | # MySQL authentication 7 | MYSQLAUTH="--user=$MYSQL_USER --password=$MYSQL_PASSWORD" 8 | 9 | # Wait for MySQL to come up. 10 | until mysql $MYSQLAUTH -e ""; do 11 | echo "Failed to connect to MySQL - retrying..." 12 | sleep 1 13 | done 14 | 15 | mysql $MYSQLAUTH -e "CREATE DATABASE IF NOT EXISTS magento" 16 | 17 | cd /var/www/magento2/htdocs 18 | bin/magento setup:install \ 19 | --db-host=mysql \ 20 | --db-name=magento \ 21 | --db-user="$MYSQL_USER" \ 22 | --db-password="$MYSQL_PASSWORD" \ 23 | --backend-frontname=admin \ 24 | --base-url=http://$PUBLIC_HOST/ \ 25 | --admin-lastname=Smith \ 26 | --admin-firstname=John \ 27 | --admin-email=john.smith@example.com \ 28 | --admin-user=admin \ 29 | --admin-password=magento2 \ 30 | 31 | # Check permissions again 32 | find . -type d -exec chmod 770 {} \; && find . -type f -exec chmod 660 {} \; && chmod u+x bin/magento 33 | chown www-data:www-data -R /var/www/magento2 34 | 35 | 36 | # In production mode we pre-compute various files 37 | php -f dev/tools/Magento/Tools/View/deploy.php 38 | php -f dev/tools/Magento/Tools/Di/compiler.php 39 | 40 | # Run the web server 41 | exec /usr/sbin/apache2 -D FOREGROUND 42 | --------------------------------------------------------------------------------