├── README.md ├── database_server ├── Dockerfile ├── mysql.sh └── supervisord.conf ├── docker-compose.yml ├── magento2 └── README.md └── web_server ├── Dockerfile └── supervisord.conf /README.md: -------------------------------------------------------------------------------- 1 | ### Setting Up Magento 2 on Multi-container Architecture Using Docker-Compose tool 2 | 3 | This repository corresponds to architecture setup as mentioned in blog https://cloudkul.com/blog/magento-2-docker-compose/. 4 | 5 | 6 | #### Docker-Compose Tool 7 | 8 | As mentioned in Docker docs, Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a Compose file to configure your application’s services. Then, using a single command, you create and start all the services from your configuration. 9 | 10 | With the help of docker-compose we can define containers to be built, their configuration, links, volumes, ports etc in a single file and it gets launched by a single command. We can add multiple servers and services just by adding them to docker-compose configuration file. This configuration file is in YAML format. 11 | 12 | Getting started with docker-compose is a few steps process: 13 | 14 | > Create a Dockerfile defining the application environment. We can create separate Dockerfile for our different services. As Dockerfile are lightweight, so our application can be replicated anywhere. 15 | 16 | > Create a docker-compose.yml file defining services that needed for application run. We can define volumes to be mapped, ports to be exposed, links to be created, arguments to be passed etc in our docker-compose.yml file. 17 | 18 | > Run ‘docker-compose build’ to create Docker image. After creating Dockerfile, docker-compose.yml and placing our volumes at right places, we can create our image. 19 | 20 | > Run ‘docker-compose up -d’ to run the docker containers. After image build up, we can run all of our containers as mentioned in configuration files by this single command. 21 | 22 | 23 | #### Dockerizing Magento 2 with Docker-Compose 24 | 25 | Docker is an open-source project that can be integrated with almost all the applications allowing scope of isolation and flexibility. It can be integrated with Magento 2 as well. Magento is an e-commerce platform written in PHP and based on zend framework available under both open-source and commercial licenses. 26 | 27 | In this project, we are using: 28 | 29 | > Operating system: Ubuntu 16.04 30 | 31 | > Web Server: Apache2 32 | 33 | > Database Server: Mysql-server-5.7 34 | 35 | > PHP version: PHP-7.1 36 | 37 | To begin with, please install docker and docker-compose on your ubuntu 16.04 server. 38 | 39 | Then follow the following steps: 40 | 41 | 1). Clone or download this repository as 42 | 43 | > git clone https://github.com/webkul/magento2-docker-compose.git 44 | 45 | 2) Set mysql root credentials and name of the database to be created . Go to ~/magento2-docker-compose/docker-compose.yml and change mysql root password in database_server in: 46 | 47 | > mysql_password= 48 | 49 | > mysql_database= 50 | 51 | 3). Download Magento 2 version you wish to dockerize and upload it in directory magento2 in parallel docker-compose.yml. 52 | 53 | > Go to https://magento.com/tech-resources/download? . 54 | 55 | 4). Build the docker image. 56 | 57 | > docker-compose build 58 | 59 | 6). Check the built image as: 60 | 61 | > docker images 62 | 63 | 7). Run the containers from built image as: 64 | 65 | > docker-compose up -d 66 | 67 | 8). Check the running docker containers by command: 68 | 69 | > docker-compose ps 70 | 71 | > docker ps 72 | 73 | Now, your server setup is all ready, now hit your domain name or IP to install Magento 2. For more details, please refer to blog https://cloudkul.com/blog/magento-2-docker-compose/. 74 | 75 | #### GETTING SUPPORT 76 | 77 | If you have any issues, contact us at support@webkul.com or raise ticket at https://webkul.uvdesk.com/ 78 | 79 | 80 | Thank you. 81 | 82 | -------------------------------------------------------------------------------- /database_server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | LABEL maintainer="Alankrit Srivastava " 4 | 5 | ARG mysql_password 6 | ARG mysql_database 7 | env MYSQL_ROOT_PASSWORD ${mysql_password} 8 | env MYSQL_DATABASE ${mysql_database} 9 | 10 | RUN apt-get update \ 11 | && echo "mysql-server-5.7 mysql-server/root_password password ${mysql_password}" | debconf-set-selections \ 12 | && echo "mysql-server-5.7 mysql-server/root_password_again password ${mysql_password}" | debconf-set-selections \ 13 | && DEBIAN_FRONTEND=noninteractive apt-get -y install mysql-server-5.7 && \ 14 | mkdir -p /var/lib/mysql && \ 15 | mkdir -p /var/run/mysqld && \ 16 | mkdir -p /var/log/mysql && \ 17 | touch /var/run/mysqld/mysqld.sock && \ 18 | touch /var/run/mysqld/mysqld.pid && \ 19 | chown -R mysql:mysql /var/lib/mysql && \ 20 | chown -R mysql:mysql /var/run/mysqld && \ 21 | chown -R mysql:mysql /var/log/mysql &&\ 22 | chmod -R 777 /var/run/mysqld/ \ 23 | && sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/mysqld.cnf \ 24 | ##install supervisor and setup supervisord.conf file 25 | && apt-get install -y supervisor nano \ 26 | && mkdir -p /var/log/supervisor 27 | CMD ["/usr/bin/supervisord"] 28 | -------------------------------------------------------------------------------- /database_server/mysql.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -u 4 | sleep 4 5 | database_connectivity_check=no 6 | var=1 7 | while [ "$database_connectivity_check" != "mysql" ]; do 8 | /etc/init.d/mysql start 9 | sleep 2 10 | database_connectivity_check=`mysqlshow --user=root --password=$MYSQL_ROOT_PASSWORD | grep -o mysql` 11 | if [ $var -ge 4 ]; then 12 | exit 1 13 | fi 14 | var=$((var+1)) 15 | done 16 | 17 | 18 | database_availability_check=`mysqlshow --user=root --password=$MYSQL_ROOT_PASSWORD | grep -ow "$MYSQL_DATABASE"` 19 | 20 | if [ "$database_availability_check" == "$MYSQL_DATABASE" ]; then 21 | exit 1 22 | else 23 | mysql -u root -p$MYSQL_ROOT_PASSWORD -e "grant all on *.* to 'root'@'%' identified by '$MYSQL_ROOT_PASSWORD';" 24 | mysql -u root -p$MYSQL_ROOT_PASSWORD -e "create database $MYSQL_DATABASE;" 25 | mysql -u root -p$MYSQL_ROOT_PASSWORD -e "grant all on $MYSQL_DATABASE.* to 'root'@'%' identified by '$MYSQL_ROOT_PASSWORD';" 26 | supervisorctl stop database_creation && supervisorctl remove database_creation 27 | echo "Database $MYSQL_DATABASE created" 28 | fi 29 | -------------------------------------------------------------------------------- /database_server/supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=true 3 | 4 | 5 | [program:mysql] 6 | command=/bin/bash -c "touch /var/run/mysqld/mysqld.sock;touch /var/run/mysqld/mysqld.pid;chown -R mysql:mysql /var/lib/mysql;chown -R mysql:mysql /var/run/mysqld;chown -R mysql:mysql /var/log/mysql;chmod -R 777 /var/run/mysqld/;/etc/init.d/mysql restart" 7 | 8 | [program:database_creation] 9 | command=/bin/bash -c "chmod a+x /etc/mysql.sh; /etc/mysql.sh" 10 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | web_server: 4 | build: 5 | context: ./web_server/ 6 | container_name: apache2 7 | volumes: 8 | - ./magento2:/var/www/html 9 | - ./web_server/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf 10 | ports: 11 | - "80:80" 12 | links: 13 | - database_server 14 | 15 | database_server: 16 | build: 17 | context: ./database_server/ 18 | args: 19 | - mysql_password=mention_your_mysql_root_password 20 | - mysql_database=mention_your_database_name 21 | container_name: mysql 22 | volumes: 23 | - ./database_server/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf 24 | - ./database_server/mysql.sh:/etc/mysql.sh 25 | ports: 26 | - "3306:3306" 27 | -------------------------------------------------------------------------------- /magento2/README.md: -------------------------------------------------------------------------------- 1 | Upload your Magento 2 files and directories here. 2 | -------------------------------------------------------------------------------- /web_server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | LABEL maintainer="Alankrit Srivastava " 4 | 5 | RUN apt-get update \ 6 | && apt-get -y install apache2 nano mysql-client \ 7 | && a2enmod rewrite \ 8 | && a2enmod headers \ 9 | && export LANG=en_US.UTF-8 \ 10 | && apt-get update \ 11 | && apt-get install -y software-properties-common \ 12 | && apt-get install -y language-pack-en-base \ 13 | && LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php \ 14 | && apt-get update \ 15 | && apt-get -y install php7.1 php7.1-curl php7.1-intl php7.1-gd php7.1-dom php7.1-mcrypt php7.1-iconv php7.1-xsl php7.1-mbstring php7.1-ctype php7.1-zip php7.1-pdo php7.1-xml php7.1-bz2 php7.1-calendar php7.1-exif php7.1-fileinfo php7.1-json php7.1-mysqli php7.1-mysql php7.1-posix php7.1-tokenizer php7.1-xmlwriter php7.1-xmlreader php7.1-phar php7.1-soap php7.1-mysql php7.1-fpm php7.1-bcmath libapache2-mod-php7.1 \ 16 | && sed -i -e"s/^memory_limit\s*=\s*128M/memory_limit = 512M/" /etc/php/7.1/apache2/php.ini \ 17 | && rm /var/www/html/* \ 18 | && sed -i "s/None/all/g" /etc/apache2/apache2.conf \ 19 | ##install supervisor and setup supervisord.conf file 20 | && apt-get install -y supervisor \ 21 | && mkdir -p /var/log/supervisor 22 | env APACHE_RUN_USER www-data 23 | env APACHE_RUN_GROUP www-data 24 | env APACHE_PID_FILE /var/run/apache2.pid 25 | env APACHE_RUN_DIR /var/run/apache2 26 | env APACHE_LOCK_DIR /var/lock/apache2 27 | env APACHE_LOG_DIR /var/log/apache2 28 | env LANG C 29 | 30 | WORKDIR /var/www/html 31 | 32 | CMD ["/usr/bin/supervisord"] 33 | 34 | -------------------------------------------------------------------------------- /web_server/supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=true 3 | 4 | [program:apache2] 5 | command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND" 6 | 7 | [program:user_permission] 8 | command=/bin/bash -c "chown -R www-data: /var/www/" 9 | --------------------------------------------------------------------------------