├── app └── .gitkeep ├── export.sql ├── .gitignore ├── runit ├── mariadb.sh ├── redis-server.sh ├── nginx.sh ├── php-fpm.sh └── queue.sh ├── partisan ├── TODO.md ├── my_init.d ├── 04_laravel_install.sh ├── 06_laravel_seed.sh ├── 05_laravel_migrate.sh ├── 01_mariadb_initialize.sh ├── 07_mariadb_import_dump.sh ├── 03_mariadb_prepare_database.sh └── 02_mariadb_secure.sh ├── docker-compose.yml ├── configs └── nginx │ └── default ├── Dockerfile └── README.md /app/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /export.sql: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | mysql 2 | -------------------------------------------------------------------------------- /runit/mariadb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "MariaDB -> start" 4 | /usr/bin/mysqld_safe 5 | -------------------------------------------------------------------------------- /runit/redis-server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "REDIS -> start" 4 | /usr/bin/redis-server 5 | -------------------------------------------------------------------------------- /partisan: -------------------------------------------------------------------------------- 1 | docker exec -it $(docker-compose ps -q) bash -c "/usr/bin/php /var/www/artisan $@" 2 | -------------------------------------------------------------------------------- /runit/nginx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "NGiNX -> start" 4 | /usr/sbin/nginx -g 'daemon off;' 5 | -------------------------------------------------------------------------------- /runit/php-fpm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "PHP-FPM7.0 -> start" 4 | /usr/sbin/php-fpm7.0 -F 5 | -------------------------------------------------------------------------------- /runit/queue.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "QUEUE -> start" 4 | /usr/bin/php /var/www/artisan queue:work --daemon 5 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | #1 Laravel should log to syslog so that docker can display laravel errors 2 | #2 cleanup shell scripts 3 | #3 finish partisan 4 | -------------------------------------------------------------------------------- /my_init.d/04_laravel_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ ! -f /var/www/artisan ]]; then 4 | echo "Laravel -> install" 5 | 6 | echo "Laravel -> installed" 7 | fi 8 | -------------------------------------------------------------------------------- /my_init.d/06_laravel_seed.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ ! -f /var/lib/mysql/status.artisan.seeded ]]; then 4 | echo "Laravel -> artisan seed" 5 | 6 | touch /var/lib/mysql/status.artisan.seeded 7 | echo "Laravel -> artisan seeded" 8 | fi 9 | -------------------------------------------------------------------------------- /my_init.d/05_laravel_migrate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ ! -f /var/lib/mysql/status.artisan.migrated ]]; then 4 | echo "Laravel -> artisan migrate" 5 | 6 | touch /var/lib/mysql/status.artisan.migrated 7 | echo "Laravel -> artisan migrated" 8 | fi 9 | -------------------------------------------------------------------------------- /my_init.d/01_mariadb_initialize.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ ! -f /var/lib/mysql/status.initialized ]]; then 4 | echo "MariaDB -> initialize" 5 | mkdir -p /var/lib/mysql 6 | chown -R mysql:mysql /var/lib/mysql 7 | /usr/bin/mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql 8 | touch /var/lib/mysql/status.initialized 9 | echo "MariaDB -> initialized" 10 | fi 11 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | larawell: 2 | build: ./ 3 | restart: always 4 | ports: 5 | - "80:80" 6 | volumes: 7 | - ./app:/var/www 8 | #- ./mysql:/var/lib/mysql 9 | - ./configs/nginx/default:/etc/nginx/sites-available/default 10 | - ./runit/nginx.sh:/etc/service/nginx/run 11 | - ./runit/php-fpm.sh:/etc/service/php-fpm/run 12 | #- ./runit/redis-server.sh:/etc/service/redis-server/run 13 | - ./runit/mariadb.sh:/etc/service/mariadb/run 14 | #- ./runit/queue.sh:/etc/service/queue/run 15 | environment: 16 | MARIA_ROOT_PASSWORD: secret 17 | TZ: Asia/Tbilisi 18 | -------------------------------------------------------------------------------- /my_init.d/07_mariadb_import_dump.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ ! -f /var/lib/mysql/status.imported ]]; then 4 | echo "MariaDB -> import" 5 | # 6 | /usr/sbin/service mysql start 7 | while [[ "$(/usr/bin/mysql -B -N -u root -e "select 1")" != 1 ]]; do 8 | sleep 1 9 | done 10 | sleep 3 11 | # 12 | /usr/bin/mysql -v -u root -p"$MARIA_ROOT_PASSWORD" homestead < /database/import.sql 13 | touch /var/lib/mysql/status.imported 14 | # 15 | /usr/sbin/service mysql stop 16 | while [[ "$(/usr/bin/pgrep mysql | /usr/bin/wc -l)" != 0 ]]; do 17 | sleep 1 18 | done 19 | sleep 3 20 | echo "MariaDB -> imported" 21 | fi 22 | -------------------------------------------------------------------------------- /my_init.d/03_mariadb_prepare_database.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ ! -f /var/lib/mysql/status.prepared ]]; then 4 | echo "MariaDB -> prepare" 5 | # 6 | /usr/sbin/service mysql start 7 | while [[ "$(/usr/bin/mysql -B -N -u root -e "select 1")" != 1 ]]; do 8 | sleep 1 9 | done 10 | sleep 3 11 | # 12 | /usr/bin/mysql -v -u root -p"$MARIA_ROOT_PASSWORD" -e "CREATE DATABASE homestead" 13 | /usr/bin/mysql -v -u root -p"$MARIA_ROOT_PASSWORD" -e "CREATE USER homestead@localhost IDENTIFIED BY 'secret'" 14 | /usr/bin/mysql -v -u root -p"$MARIA_ROOT_PASSWORD" -e "GRANT ALL PRIVILEGES ON homestead.* TO homestead@localhost" 15 | touch /var/lib/mysql/status.prepared 16 | # 17 | /usr/sbin/service mysql stop 18 | while [[ "$(/usr/bin/pgrep mysql | /usr/bin/wc -l)" != 0 ]]; do 19 | sleep 1 20 | done 21 | sleep 3 22 | echo "MariaDB -> prepared" 23 | fi 24 | -------------------------------------------------------------------------------- /my_init.d/02_mariadb_secure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ ! -f /var/lib/mysql/status.secured ]]; then 4 | echo "MariaDB -> secure" 5 | # 6 | /usr/sbin/service mysql start 7 | while [[ "$(/usr/bin/mysql -B -N -u root -e "select 1")" != 1 ]]; do 8 | sleep 1 9 | done 10 | sleep 3 11 | # 12 | /usr/bin/mysql -v -u root -p"$MARIA_ROOT_PASSWORD" -e "UPDATE mysql.user SET Password=PASSWORD('$MARIA_ROOT_PASSWORD') WHERE User='root'" 13 | /usr/bin/mysql -v -u root -p"$MARIA_ROOT_PASSWORD" -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')" 14 | /usr/bin/mysql -v -u root -p"$MARIA_ROOT_PASSWORD" -e "DELETE FROM mysql.user WHERE User=''" 15 | /usr/bin/mysql -v -u root -p"$MARIA_ROOT_PASSWORD" -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" 16 | /usr/bin/mysql -v -u root -p"$MARIA_ROOT_PASSWORD" -e "FLUSH PRIVILEGES" 17 | touch /var/lib/mysql/status.secured 18 | # 19 | /usr/sbin/service mysql stop 20 | while [[ "$(/usr/bin/pgrep mysql | /usr/bin/wc -l)" != 0 ]]; do 21 | sleep 1 22 | done 23 | sleep 3 24 | echo "MariaDB -> secured" 25 | fi 26 | -------------------------------------------------------------------------------- /configs/nginx/default: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | 4 | root /var/www/public; 5 | index index.html index.htm index.php; 6 | 7 | server_name localhost; 8 | 9 | access_log /var/log/nginx/localhost.com-access.log; 10 | error_log /var/log/nginx/localhost.com-error.log error; 11 | 12 | charset utf-8; 13 | 14 | location / { 15 | try_files $uri $uri/ /index.html /index.php?$query_string; 16 | } 17 | 18 | location = /favicon.ico { log_not_found off; access_log off; } 19 | location = /robots.txt { access_log off; log_not_found off; } 20 | 21 | error_page 404 /index.php; 22 | 23 | # pass the PHP scripts to php7-fpm 24 | location ~ index.php$ { 25 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 26 | fastcgi_pass unix:/run/php/php7.0-fpm.sock; 27 | fastcgi_index index.php; 28 | include fastcgi_params; 29 | include fastcgi.conf; 30 | fastcgi_param LARA_ENV local; # Environment variable for Laravel 31 | fastcgi_param HTTPS off; 32 | } 33 | 34 | # Deny . (dot) file access: .git .svn etc. 35 | location ~ /\. { 36 | deny all; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # See https://github.com/phusion/baseimage-docker/blob/master/Changelog.md for 2 | # a list of version numbers. 3 | FROM phusion/baseimage:0.9.19 4 | 5 | # Use baseimage-docker's init system. 6 | CMD ["/sbin/my_init"] 7 | 8 | # Avoid ERROR: invoke-rc.d: policy-rc.d denied execution of start. 9 | RUN sed -i "s/^exit 101$/exit 0/" /usr/sbin/policy-rc.d 10 | 11 | RUN apt-get update 12 | RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y \ 13 | mariadb-server mariadb-client \ 14 | nginx \ 15 | nodejs npm \ 16 | php7.0-cli php7.0-fpm php7.0-gd php7.0-mcrypt php7.0-mbstring php7.0-xml php7.0-zip php7.0-mysql php7.0-curl \ 17 | redis-server \ 18 | git 19 | 20 | # This is a fix for 21 | # ERROR: unable to bind listening socket for address '/run/php/php7.0-fpm.sock': No such file or directory (2) 22 | # ERROR: FPM initialization failed 23 | RUN service php7.0-fpm start 24 | 25 | # 26 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 27 | 28 | # 29 | RUN mkdir -p /etc/my_init.d 30 | ADD my_init.d /etc/my_init.d 31 | 32 | # 33 | RUN mkdir /database 34 | ADD export.sql /database/import.sql 35 | 36 | # 37 | RUN crontab -l | { cat; echo "* * * * * /usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1"; } | crontab - 38 | 39 | # 40 | EXPOSE 80 3306 6379 3000 41 | 42 | # Clean up APT when done. 43 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # larawell 2 | Monolithic docker container to run your Laravel apps: MariaDB/Redis/Nginx/PHP7.0-Fpm 3 | 4 | #### Why monolothic? 5 | 6 | Larawell uses [phusion/baseimage](https://github.com/phusion/baseimage-docker#wait-i-thought-docker-is-about-running-a-single-process-in-a-container) and shares same convictions about running multiple logical services in a single container. 7 | 8 | #### Includes 9 | 10 | + MariaDB 11 | + Redis 12 | + Nginx 13 | + PHP7.0-Fpm 14 | + NodeJs 15 | + npm 16 | + schedule:run 17 | + queue:work 18 | + composer 19 | 20 | Both schedule:run (cron) and queue:work (service) are included and running properly by default. There is no other docker container for Laravel that offers working cron or queue, so if you plan to run full featured Laravel app this should be your container of choice. 21 | 22 | Note: Larawell uses `queue:work --daemon` instead of `queue:listen` as later was causing high CPU spikes. `docker stats` was reporting 10% CPU utlizaition on `queue:listen` versus hovering around 0.5% with `queue:work --daemon`. 23 | 24 | #### Scripts 25 | 26 | Container is bundled with 7 helper bash scripts. Few of them are required for correct functioning and some can be enabled on user discretion. 27 | 28 | + 01_mariadb_initialize.sh - 29 | + 02_mariadb_secure.sh - 30 | + 03_mariadb_prepare_database.sh - 31 | + 04_laravel_install.sh - 32 | + 05_laravel_migrate.sh - 33 | + 06_laravel_seed.sh - 34 | + 07_mariadb_import_dump.sh - 35 | 36 | #### Quick start 37 | 38 | To build, run and daemonize you can `docker-compose up -d --build`. 39 | 40 | Have a look inside `docker-compose.yml` you can enable redis and queue there, disabled by default. 41 | 42 | #### pArtisan 43 | 44 | To run artisan commands from host you can use `partisan` tool inside larawell root. 45 | --------------------------------------------------------------------------------