From c4677b0278d806d213e60a6f5bbcb20be25eb8fd Mon Sep 17 00:00:00 2001 From: Tim de Pater Date: Mon, 15 Feb 2016 18:20:56 +0100 Subject: [PATCH] Intial commit --- Dockerfile | 4 ++++ README.md | 20 +++++++++++++++++ config/nginx.conf | 56 ++++++++++++++++++++++++++++++++++++++++++++++ config/php.ini | 2 ++ docker-compose.yml | 20 +++++++++++++++++ src/index.php | 2 ++ 6 files changed, 104 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 config/nginx.conf create mode 100644 config/php.ini create mode 100644 docker-compose.yml create mode 100644 src/index.php diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..547af7b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM php:7.0-fpm + +COPY config/php.ini /usr/local/etc/php/conf.d/custom.ini +ADD ./src/ /var/www/html/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..9ec5fca --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +Docker PHP-FPM & Nginx setup +============================ +Example PHP-FPM & Nginx setup for Docker using docker-compose. + +Usage +---- +Add this to your hosts file: + + 127.0.0.1 docker-app.dev + +Start the Docker containers: + + docker-compose up + +See the PHP info on http://docker-app.dev + +Resources & inspiration +----------------------- +https://ejosh.co/de/2015/09/how-to-link-docker-containers-together +https://github.com/johanan/Ansible-and-Docker diff --git a/config/nginx.conf b/config/nginx.conf new file mode 100644 index 0000000..92717cc --- /dev/null +++ b/config/nginx.conf @@ -0,0 +1,56 @@ +server { + listen 80; ## listen for ipv4; this line is default and implied + listen [::]:80 default ipv6only=on; ## listen for ipv6 + + root /var/www/html; + index index.php index.html index.htm; + + # Make site accessible from http://localhost/ + server_name docker-app.dev; + + # Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html + sendfile off; + + # Add stdout logging + + error_log /dev/stderr info; + access_log /dev/stdout; + + location / { + # First attempt to serve request as file, then + # as directory, then fall back to index.html + try_files $uri $uri/ /index.php?q=$uri&$args; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass fpm:9000; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SCRIPT_NAME $fastcgi_script_name; + fastcgi_index index.php; + include fastcgi_params; + } + + location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { + expires 5d; + } + + # deny access to . files, for security + # + location ~ /\. { + log_not_found off; + deny all; + } +} diff --git a/config/php.ini b/config/php.ini new file mode 100644 index 0000000..2311cd1 --- /dev/null +++ b/config/php.ini @@ -0,0 +1,2 @@ +[Date] +date.timezone="Europe/Amsterdam" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..378d0f2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +appdata: + image: debian:jessie + volumes: + - ./src:/var/www/html + +fpm: + build: . + volumes_from: + - appdata + +nginx: + image: nginx:1.9 + links: + - fpm + volumes: + - ./config/nginx.conf:/etc/nginx/conf.d/app.conf:ro + volumes_from: + - appdata + ports: + - 80:80 diff --git a/src/index.php b/src/index.php new file mode 100644 index 0000000..61ace19 --- /dev/null +++ b/src/index.php @@ -0,0 +1,2 @@ +