From 21cae0d51e816983cb3bc9f1dba48fd5fd050331 Mon Sep 17 00:00:00 2001 From: pierreozoux <pierre@ozoux.net> Date: Wed, 18 Feb 2015 20:04:56 +0000 Subject: [PATCH] Adds nginx php --- dockerfiles/services/nginx-php/Dockerfile | 30 +++++++++++++++++++ dockerfiles/services/nginx-php/basic.conf | 5 ++++ dockerfiles/services/nginx-php/entrypoint.sh | 12 ++++++++ dockerfiles/services/nginx-php/environment | 6 ++++ dockerfiles/services/nginx-php/mysql-check.sh | 23 ++++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 dockerfiles/services/nginx-php/Dockerfile create mode 100644 dockerfiles/services/nginx-php/basic.conf create mode 100755 dockerfiles/services/nginx-php/entrypoint.sh create mode 100644 dockerfiles/services/nginx-php/environment create mode 100644 dockerfiles/services/nginx-php/mysql-check.sh diff --git a/dockerfiles/services/nginx-php/Dockerfile b/dockerfiles/services/nginx-php/Dockerfile new file mode 100644 index 0000000..5d0c7d6 --- /dev/null +++ b/dockerfiles/services/nginx-php/Dockerfile @@ -0,0 +1,30 @@ +FROM nginx + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update && apt-get install -y \ + mysql-client \ + php5-fpm \ + php5-mysql \ + curl && \ + rm -rf /var/lib/apt/lists/* && \ + rm -rf /etc/nginx/conf.d/* && \ + rm -rf /usr/share/nginx/html/* && \ + mkdir -p /etc/nginx/external && \ + sed -i 's/access_log.*/access_log \/dev\/stdout;/g' /etc/nginx/nginx.conf && \ + sed -i 's/error_log.*/error_log \/dev\/stdout info;/g' /etc/nginx/nginx.conf && \ + sed -i 's/^pid/daemon off;\npid/g' /etc/nginx/nginx.conf && \ + sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php5/fpm/php.ini + +ADD basic.conf /etc/nginx/conf.d/basic.conf +ADD entrypoint.sh /opt/entrypoint.sh +RUN chmod u+x /opt/entrypoint.sh + +ADD mysql-check.sh /opt/mysql-check.sh +RUN chmod u+x /opt/mysql-check.sh + +ADD environment /etc/environment + +ENTRYPOINT ["/opt/entrypoint.sh"] +CMD ["nginx"] + diff --git a/dockerfiles/services/nginx-php/basic.conf b/dockerfiles/services/nginx-php/basic.conf new file mode 100644 index 0000000..e7c093c --- /dev/null +++ b/dockerfiles/services/nginx-php/basic.conf @@ -0,0 +1,5 @@ +# hide nginx version +server_tokens off; + +# add nosniff header (https://www.owasp.org/index.php/List_of_useful_HTTP_headers) +add_header X-Content-Type-Options nosniff; diff --git a/dockerfiles/services/nginx-php/entrypoint.sh b/dockerfiles/services/nginx-php/entrypoint.sh new file mode 100755 index 0000000..ad97c03 --- /dev/null +++ b/dockerfiles/services/nginx-php/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/bash -eux + +/etc/init.d/php5-fpm start +chmod a+rwx /var/run/php5-fpm.sock + +echo "127.0.0.1 ${URL}" >> /etc/hosts + +# exec CMD +echo ">> exec docker CMD" +echo "$@" +"$@" + diff --git a/dockerfiles/services/nginx-php/environment b/dockerfiles/services/nginx-php/environment new file mode 100644 index 0000000..15719f9 --- /dev/null +++ b/dockerfiles/services/nginx-php/environment @@ -0,0 +1,6 @@ +#!/bin/bash -eux + +DB_HOST=db +DB_PORT=${DB_PORT_3306_TCP_PORT:-${DB_PORT}} +DB_PORT=${DB_1_PORT_3306_TCP_PORT:-${DB_PORT}} + diff --git a/dockerfiles/services/nginx-php/mysql-check.sh b/dockerfiles/services/nginx-php/mysql-check.sh new file mode 100644 index 0000000..46a2745 --- /dev/null +++ b/dockerfiles/services/nginx-php/mysql-check.sh @@ -0,0 +1,23 @@ +#!/bin/bash -eux + +source /etc/environment + +echo "=> Trying to connect to MySQL/MariaDB using:" +echo "========================================================================" +echo " Database Host Address: $DB_HOST" +echo " Database Port number: $DB_PORT" +echo " Database Username: $DB_USER" +echo " Database Password: $DB_PASS" +echo "========================================================================" + +for ((i=0;i<10;i++)) +do + DB_CONNECTABLE=$(mysql -u$DB_USER -p$DB_PASS -h$DB_HOST -P$DB_PORT -e 'status' >/dev/null 2>&1; echo "$?") + if [[ DB_CONNECTABLE -eq 0 ]]; then + exit 0 + fi + sleep 5 +done + +exit 1 + -- GitLab