From 16aaa4f31f18d88c45386c9de8d882f2cc13b59f Mon Sep 17 00:00:00 2001 From: Tim de Pater Date: Wed, 24 Feb 2016 11:08:50 +0100 Subject: [PATCH] Rewrote the example setup to have only one Docker container --- .travis.yml | 12 ++++++++++++ Dockerfile | 30 ++++++++++++++++++++++++++++-- README.md | 19 +++---------------- {nginx => config}/nginx.conf | 25 +++++++++---------------- {fpm => config}/php.ini | 0 config/supervisord.conf | 16 ++++++++++++++++ docker-compose.yml | 19 ------------------- fpm/Dockerfile | 3 --- nginx/Dockerfile | 9 --------- src/test.html | 1 + 10 files changed, 69 insertions(+), 65 deletions(-) create mode 100644 .travis.yml rename {nginx => config}/nginx.conf (63%) rename {fpm => config}/php.ini (100%) create mode 100644 config/supervisord.conf delete mode 100644 docker-compose.yml delete mode 100644 fpm/Dockerfile delete mode 100644 nginx/Dockerfile create mode 100644 src/test.html diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5688aa2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +env: + global: + - COMMIT=${TRAVIS_COMMIT::8} + - REPO=trafex/php-nginx + +script: + - docker --version + - export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH ; fi` + - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS + - docker build -t $REPO:$COMMIT . + - docker tag $REPO:$COMMIT $REPO:$TAG + - docker push $REPO diff --git a/Dockerfile b/Dockerfile index b4bac17..400e96f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,31 @@ -FROM debian:jessie +FROM php:7.0-fpm +# Install Nginx +ENV NGINX_VERSION 1.9.11-1~jessie + +RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 \ + && echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list \ + && apt-get update \ + && apt-get install -y ca-certificates nginx=${NGINX_VERSION} gettext-base \ + && rm -rf /var/lib/apt/lists/* + +# Install supervisor +RUN apt-get update && apt-get install -y supervisor + +# Configure nginx +RUN rm /etc/nginx/conf.d/default.conf +COPY config/nginx.conf /etc/nginx/conf.d/nginx.conf + +# Configure supervisor +COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +# Configure PHP-FPM +COPY config/php.ini /usr/local/etc/php/conf.d/custom.ini + +# Add application +RUN mkdir -p /var/www/html +WORKDIR /var/www/html COPY src/ /var/www/html/ -VOLUME /var/www/html/ +EXPOSE 80 443 +CMD ["/usr/bin/supervisord"] diff --git a/README.md b/README.md index 50690d7..0d9c27f 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,14 @@ Docker PHP-FPM & Nginx setup ============================ -Example PHP-FPM & Nginx setup for Docker using docker-compose. +Example PHP-FPM 7 & Nginx 1.9 setup for Docker 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 - -Docker Hub ----------- -The containers can be found on the Docker hub: - -- [trafex/example-appdata](https://hub.docker.com/r/trafex/example-appdata) -- [trafex/example-nginx](https://hub.docker.com/r/trafex/example-nginx) -- [trafex/example-phpfpm](https://hub.docker.com/r/trafex/example-phpfpm) + sudo docker run -p 80:80 trafex/php-nginx +See the PHP info on http://localhost, or the static html page on http://localhost/test.html Resources & inspiration ----------------------- diff --git a/nginx/nginx.conf b/config/nginx.conf similarity index 63% rename from nginx/nginx.conf rename to config/nginx.conf index b6f72b8..abab62b 100644 --- a/nginx/nginx.conf +++ b/config/nginx.conf @@ -1,31 +1,24 @@ server { - listen 80; ## listen for ipv4; this line is default and implied - listen [::]:80 default ipv6only=on; ## listen for ipv6 + listen [::]:80 default_server; + listen 80 default_server; + server_name _; - 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 + root /var/www/html; + index index.php index.html; - error_log /dev/stderr info; + 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 + # as directory, then fall back to index.php 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; @@ -36,7 +29,7 @@ server { location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass UPSTREAM_HOST:UPSTREAM_PORT; + fastcgi_pass localhost:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_index index.php; diff --git a/fpm/php.ini b/config/php.ini similarity index 100% rename from fpm/php.ini rename to config/php.ini diff --git a/config/supervisord.conf b/config/supervisord.conf new file mode 100644 index 0000000..18e1ab8 --- /dev/null +++ b/config/supervisord.conf @@ -0,0 +1,16 @@ +[supervisord] +nodaemon=true + +[program:php-fpm] +command=php-fpm +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:nginx] +command=nginx -g 'daemon off;' +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 4edb78c..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,19 +0,0 @@ -appdata: - build: . - -fpm: - build: ./fpm - volumes_from: - - appdata - -nginx: - build: ./nginx - links: - - fpm - volumes_from: - - appdata - ports: - - 80:80 - environment: - - UPSTREAM_HOST=fpm - - UPSTREAM_PORT=9000 diff --git a/fpm/Dockerfile b/fpm/Dockerfile deleted file mode 100644 index caf5d7a..0000000 --- a/fpm/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM php:7.0-fpm - -COPY php.ini /usr/local/etc/php/conf.d/custom.ini diff --git a/nginx/Dockerfile b/nginx/Dockerfile deleted file mode 100644 index efdcb2f..0000000 --- a/nginx/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM nginx:1.9 - -COPY nginx.conf /etc/nginx/conf.d/app.conf - -CMD /bin/bash -c envsubst < /etc/nginx/conf.d/app.conf.template > /etc/nginx/conf.d/app.conf && nginx -g 'daemon off;' - -CMD sed -i 's/UPSTREAM_HOST/'"$UPSTREAM_HOST"'/g' /etc/nginx/conf.d/app.conf \ - && sed -i 's/UPSTREAM_PORT/'"$UPSTREAM_PORT"'/g' /etc/nginx/conf.d/app.conf \ - && nginx -g 'daemon off;' diff --git a/src/test.html b/src/test.html new file mode 100644 index 0000000..23db8c8 --- /dev/null +++ b/src/test.html @@ -0,0 +1 @@ +This should also work and be served by Nginx