From 05a83d383f7132decce6e1ff2b63652d75808869 Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Fri, 6 May 2016 17:04:02 +0300 Subject: [PATCH] Major updates. - upgrade docker compose to v2 - build images locally instead of pulling them from the registry - separate php container form nginx container - support all the php versions including php 7.0 - remove beanstalked container to be optionally added later by the user --- .gitignore | 1 + data/Dockerfile | 5 + docker-compose.yml | 113 ++++++++++--------- mysql/Dockerfile | 9 ++ nginx/Dockerfile | 14 +++ settings/nginx/default => nginx/laravel.conf | 7 +- nginx/nginx.conf | 29 +++++ php/Dockerfile | 16 +++ php/laravel.ini | 3 + php/laravel.pool.conf | 76 +++++++++++++ redis/Dockerfile | 9 ++ 11 files changed, 227 insertions(+), 55 deletions(-) create mode 100644 .gitignore create mode 100644 data/Dockerfile create mode 100644 mysql/Dockerfile create mode 100644 nginx/Dockerfile rename settings/nginx/default => nginx/laravel.conf (86%) create mode 100644 nginx/nginx.conf create mode 100644 php/Dockerfile create mode 100644 php/laravel.ini create mode 100644 php/laravel.pool.conf create mode 100644 redis/Dockerfile diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..df1a13b2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/logs \ No newline at end of file diff --git a/data/Dockerfile b/data/Dockerfile new file mode 100644 index 00000000..15869d36 --- /dev/null +++ b/data/Dockerfile @@ -0,0 +1,5 @@ +FROM debian:jessie + +MAINTAINER Mahmoud Zalt + +CMD ["true"] diff --git a/docker-compose.yml b/docker-compose.yml index d668f74f..38fcf335 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,58 +1,65 @@ -# PHP + NGINX Container #---------------------------------- -php-nginx: - image: laradock/php56nginx:0.1.0 - container_name: php-nginx - ports: - - "80:80" - volumes: - - ./settings/nginx:/etc/nginx/sites-available - - ../:/var/www - - ./logs/nginx:/var/log/nginx - links: - - mysql - - redis - privileged: true +version: '2' +services: -# MySQL Container #---------------------------------------- -mysql: - image: laradock/mysql:0.1.0 - container_name: mysql - ports: - - "3306:3306" - volumes_from: - - data - environment: - MYSQL_DATABASE: homestead - MYSQL_USER: homestead - MYSQL_PASSWORD: secret - privileged: true +### Nginx Server Container ################################## -# Redis Container #---------------------------------------- -redis: - image: laradock/redis:0.1.0 - container_name: redis - ports: - - "6379:6379" - volumes_from: - - data - volumes: - - ./logs/redis:/var/log/redis - privileged: true + nginx: + build: ./nginx + container_name: nginx + volumes_from: + - php + volumes: + - ./logs/nginx/:/var/log/nginx + ports: + - "80:80" + links: + - php -# Data Volume Container #---------------------------------- -data: - image: laradock/data:0.1.0 - container_name: data - volumes: - - /var/lib/mysql - - /var/lib/redis +### PHP Container ########################################### -# Beanstalkd Container #----------------------------------- -# beanstalkd: -# image: laradock/beanstalkd:0.1.0 -# container_name: beanstalkd -# ports: -# - "11300:11300" -# privileged: true + php: + build: ./php + container_name: php + volumes: + - ../:/var/www/laravel + - ./logs/php/:/usr/local/var/log + expose: + - "9000" + links: + - mysql -#---------------------------------------------------------- +### MySQL Container ######################################### + + mysql: + build: ./mysql + container_name: mysql + volumes_from: + - data + ports: + - "3306:3306" + environment: + MYSQL_DATABASE: homestead + MYSQL_USER: homestead + MYSQL_PASSWORD: secret + MYSQL_ROOT_PASSWORD: root + +### Redis Container ######################################### + + redis: + build: ./redis + container_name: redis + volumes_from: + - data + ports: + - "6379:6379" + +### DATA Container ########################################## + + data: + build: ./data + container_name: data + volumes: + - /var/lib/mysql + - /var/lib/redis + +### Add more Containers below ############################### diff --git a/mysql/Dockerfile b/mysql/Dockerfile new file mode 100644 index 00000000..b7206cc7 --- /dev/null +++ b/mysql/Dockerfile @@ -0,0 +1,9 @@ +FROM mysql:latest + +MAINTAINER Mahmoud Zalt + +VOLUME /var/lib/mysql + +CMD ["mysqld"] + +EXPOSE 3306 diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 00000000..eb114931 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,14 @@ +FROM nginx:latest + +MAINTAINER Mahmoud Zalt + +ADD nginx.conf /etc/nginx/ +ADD laravel.conf /etc/nginx/sites-available/ + +RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf + +RUN usermod -u 1000 www-data + +CMD ["nginx"] + +EXPOSE 80 443 diff --git a/settings/nginx/default b/nginx/laravel.conf similarity index 86% rename from settings/nginx/default rename to nginx/laravel.conf index a6865eaa..432c2a71 100644 --- a/settings/nginx/default +++ b/nginx/laravel.conf @@ -2,7 +2,7 @@ server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; - root /var/www/public; + root /var/www/laravel/public; index index.php index.html index.htm; location / { @@ -11,7 +11,7 @@ server { location ~ \.php$ { try_files $uri /index.php =404; - fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_pass php-upstream; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; @@ -21,3 +21,6 @@ server { deny all; } } + + + diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 00000000..07708308 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,29 @@ +user www-data; +worker_processes 4; +pid /run/nginx.pid; + +events { + worker_connections 2048; + multi_accept on; + use epoll; +} + +http { + server_tokens off; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 15; + types_hash_max_size 2048; + include /etc/nginx/mime.types; + default_type application/octet-stream; + access_log off; + error_log off; + gzip on; + gzip_disable "msie6"; + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-available/*; + open_file_cache max=100; +} + +daemon off; diff --git a/php/Dockerfile b/php/Dockerfile new file mode 100644 index 00000000..d5b7da81 --- /dev/null +++ b/php/Dockerfile @@ -0,0 +1,16 @@ +FROM php:7.0-fpm + +MAINTAINER Mahmoud Zalt + +ADD ./laravel.ini /usr/local/etc/php/conf.d +ADD ./laravel.pool.conf /usr/local/etc/php-fpm.d/ + +# Install extensions using the helper script provided by the base image +RUN docker-php-ext-install \ + pdo_mysql + +RUN usermod -u 1000 www-data + +CMD ["php-fpm"] + +EXPOSE 9000 diff --git a/php/laravel.ini b/php/laravel.ini new file mode 100644 index 00000000..b0e572de --- /dev/null +++ b/php/laravel.ini @@ -0,0 +1,3 @@ +date.timezone = UTC +display_errors = Off +log_errors = On diff --git a/php/laravel.pool.conf b/php/laravel.pool.conf new file mode 100644 index 00000000..ab2a4f1f --- /dev/null +++ b/php/laravel.pool.conf @@ -0,0 +1,76 @@ +; Unix user/group of processes +; Note: The user is mandatory. If the group is not set, the default user's group +; will be used. +user = www-data +group = www-data + +; The address on which to accept FastCGI requests. +; Valid syntaxes are: +; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on +; a specific port; +; 'port' - to listen on a TCP socket to all addresses on a +; specific port; +; '/path/to/unix/socket' - to listen on a unix socket. +; Note: This value is mandatory. +listen = 0.0.0.0:9000 + +; Choose how the process manager will control the number of child processes. +; Possible Values: +; static - a fixed number (pm.max_children) of child processes; +; dynamic - the number of child processes are set dynamically based on the +; following directives. With this process management, there will be +; always at least 1 children. +; pm.max_children - the maximum number of children that can +; be alive at the same time. +; pm.start_servers - the number of children created on startup. +; pm.min_spare_servers - the minimum number of children in 'idle' +; state (waiting to process). If the number +; of 'idle' processes is less than this +; number then some children will be created. +; pm.max_spare_servers - the maximum number of children in 'idle' +; state (waiting to process). If the number +; of 'idle' processes is greater than this +; number then some children will be killed. +; ondemand - no children are created at startup. Children will be forked when +; new requests will connect. The following parameter are used: +; pm.max_children - the maximum number of children that +; can be alive at the same time. +; pm.process_idle_timeout - The number of seconds after which +; an idle process will be killed. +; Note: This value is mandatory. +pm = dynamic + +; The number of child processes to be created when pm is set to 'static' and the +; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. +; This value sets the limit on the number of simultaneous requests that will be +; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. +; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP +; CGI. The below defaults are based on a server without much resources. Don't +; forget to tweak pm.* to fit your needs. +; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' +; Note: This value is mandatory. +pm.max_children = 20 + +; The number of child processes created on startup. +; Note: Used only when pm is set to 'dynamic' +; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 +pm.start_servers = 2 + +; The desired minimum number of idle server processes. +; Note: Used only when pm is set to 'dynamic' +; Note: Mandatory when pm is set to 'dynamic' +pm.min_spare_servers = 1 + +; The desired maximum number of idle server processes. +; Note: Used only when pm is set to 'dynamic' +; Note: Mandatory when pm is set to 'dynamic' +pm.max_spare_servers = 3 + +;--------------------- + +; Make specific Docker environment variables available to PHP +env[DB_1_ENV_MYSQL_DATABASE] = $DB_1_ENV_MYSQL_DATABASE +env[DB_1_ENV_MYSQL_USER] = $DB_1_ENV_MYSQL_USER +env[DB_1_ENV_MYSQL_PASSWORD] = $DB_1_ENV_MYSQL_PASSWORD + +catch_workers_output = yes diff --git a/redis/Dockerfile b/redis/Dockerfile new file mode 100644 index 00000000..a0a4797b --- /dev/null +++ b/redis/Dockerfile @@ -0,0 +1,9 @@ +FROM redis:latest + +MAINTAINER Mahmoud Zalt + +#COPY redis.conf /usr/local/etc/redis/redis.conf + +CMD [ "redis-server" ] + +EXPOSE 6379