manage apache-fpm + fix alpine-symfony

This commit is contained in:
a-sansara 2016-08-12 04:06:57 +02:00
parent 79cb538ef5
commit 48d9fc2840
24 changed files with 289 additions and 16 deletions

View File

@ -3,6 +3,7 @@
- [index][1]
- [pluie/alpine][2] ( < 10 MB ) Alpine/3.4
- [pluie/alpine-apache][3] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24
- [pluie/alpine-apache-fpm][7] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24 Fpm
- [pluie/alpine-symfony][6] ( ~ 81 MB )
- [pluie/alpine-mysql][4] ( ~172 MB ) Mysql/5.5.47 ( MariaDB )
- [docker tips][5]
@ -31,6 +32,8 @@ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}
172.22.0.4 pma.docker
172.22.0.5 bo-payment.docker
172.22.0.6 wordpress.docker
172.22.0.7 symfony.docker
172.22.0.8 afpm.docker
# <
```
@ -74,6 +77,7 @@ docker stats container
[gogs.docker] (http://gogs.docker)
[bo-payment.docker] (http://bo-payment.docker)
[wordpress.docker] (http://wordpress.docker)
[symfony.docker] (http://symfony.docker)
#### Mysql
```
@ -117,17 +121,6 @@ docker run --name apache --restart=always \
-d pluie/alpine-apache
```
### Symfony
```
cd /home/dev/docker
docker run --name symfony --restart=always \
--net home0 -h symfony.docker --ip 172.22.0.7 --link=mysql:db \
-e HTTP_SERVER_NAME=symfony \
-e SYMFONY_VERSION=2.8 \
-v $(pwd)/repo/myapp:/app \
-d pluie/alpine-symfony
```
#### Wordpress
```
cd /home/dev/docker
@ -137,10 +130,34 @@ docker run --name wordpress --restart=always \
-v $(pwd)/repo/blog:/app \
-e HTTP_SERVER_NAME=wordpress.docker \
-d pluie/alpine-apache
```
### Symfony
```
cd /home/dev/docker
docker run --name symfony --restart=always \
--net home0 -h symfony.docker --ip 172.22.0.7 --link=mysql:db \
-e HTTP_SERVER_NAME=symfony \
-e SYMFONY_VERSION=2.8 \
-v $(pwd)/repo/myapp:/app \
-d pluie/alpine-symfony
```
#### ApacheFpm
```
cd /home/dev/docker
docker run --name afpm --restart=always \
--net home0 -h bo-payment.docker --ip 172.22.0.8 --link mysql:db \
-v $(pwd)/repo/afpm:/app \
-e HTTP_SERVER_NAME=afpm.docker \
-d pluie/alpine-apache-fpm
```
[1]: https://github.com/pluie-org/docker-images
[2]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine
[3]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-mysql
[4]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache
[7]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache-fpm
[5]: https://github.com/pluie-org/docker-images/blob/master/DOCKER.md
[6]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-symfony

View File

@ -7,6 +7,7 @@ various based images for Docker
- [index][1]
- [pluie/alpine][2] ( < 10 MB ) Alpine/3.4
- [pluie/alpine-apache][3] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24
- [pluie/alpine-apache-fpm][7] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24 Fpm
- [pluie/alpine-symfony][6] ( ~ 81 MB )
- [pluie/alpine-mysql][4] ( ~172 MB ) Mysql/5.5.47 ( MariaDB )
- [docker tips][5]
@ -75,5 +76,6 @@ you can keep same __build__ script in any project
[2]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine
[3]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-mysql
[4]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache
[7]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache-fpm
[5]: https://github.com/pluie-org/docker-images/blob/master/DOCKER.md
[6]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-symfony

1
pluie/alpine-apache-fpm/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
files.tar

View File

@ -0,0 +1,22 @@
# @app pluie/alpine-apache
# @author a-Sansara https://git.pluie.org/pluie/docker-images
FROM pluie/alpine
MAINTAINER a-Sansara https://github.com/a-sansara
ADD files.tar /scripts
ENV SHENV_NAME=ApacheFpm \
SHENV_COLOR=67 \
HTTP_SERVER_NAME=fpm.docker \
WWW_DIR=www \
WWW_INDEX=index \
FIX_OWNERSHIP=1 \
TZ=Europe/Paris
EXPOSE 80
VOLUME /etc/php5/fpm.d/
RUN bash /scripts/install.sh

View File

@ -0,0 +1,89 @@
# pluie/alpine-apache
- [index][1]
- [pluie/alpine][2] ( < 10 MB ) Alpine/3.4
- [pluie/alpine-apache][3] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24
- [pluie/alpine-apache-fpm][7] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24 Fpm
- [pluie/alpine-symfony][6] ( ~ 81 MB )
- [pluie/alpine-mysql][4] ( ~172 MB ) Mysql/5.5.47 ( MariaDB )
- [docker tips][5]
Extend pluie/alpine with __apache 2.4.23__ and __php 5.6.24__
- error log are attached to stdout
- no need port redirection
- you can use env var at container creation : __HTTP_SERVER_NAME__ (default : docker-site.dev ortherwise edit app/vhost later)
- you can still use ever your local http & sql server while your container(s) are running
## Image Size
- image ~ 50 MB
## ENV variables
```
HTTP_SERVER_NAME=apache.docker # apache ServerName
WWW_DIR=www # DocumentRoot relative to volume
WWW_INDEX=index.php # DirectoryIndex
FIX_OWNERSHIP=1 #
```
### Inherit ENV variables
```
SHENV_CTX=LOCAL # LOCAL|INT|PROD change context bg color
SHENV_NAME=Apache # container name
SHENV_COLOR=67 # ANSI EXTENDED COLOR CODE
TZ=Europe/Paris # TIMEZONE
```
## Image Volumes
__/app__ directory is a docker volume bind to your app project (silex/symfony etc)
__/app/$WWW_DIR__ is the documentRoot.
put only your entry point and static files to the documentRoot directory, no your app sources
(__/app__ directory is design for this).
__/app/vhost__ is your app vhost configuration file (with a serverName directive).
by default it use the apache rewrite module to redirect all uri to entry point $WWW_INDEX
```
/app/ # your application directory
|
|---- $WWW_DIR/ # documentRoot
|
|---- vhost # apache app vhost
```
## Image Usage
chdir to your project directory
```
$ docker run --name apache -it --link=mysql:db1 -v $(pwd):/app pluie/alpine-apache
```
or
```
$ docker run --name apache -it --link=mysql:db1 -e HTTP_SERVER_NAME=yourServerName -v $(pwd):/app pluie/alpine-apache
```
## Controling http server
```
$ docker exec -it apache "httpd -k restart"
```
for more commands :
```
$ docker exec -it apache "httpd -h"
```
[1]: https://github.com/pluie-org/docker-images
[2]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine
[3]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-mysql
[4]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache
[7]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache-fpm
[5]: https://github.com/pluie-org/docker-images/blob/master/DOCKER.md
[6]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-symfony

22
pluie/alpine-apache-fpm/build Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
# @app pluie/alpine-apache
# @author a-Sansara https://git.pluie.org/pluie/docker-images
Ctitle="\033[1;38;5;15;1;48;5;30m"
Citem="\033[1;38;5;36m"
Coff="\033[m"
DOCKDIR=$(dirname "$(readlink -f ${BASH_SOURCE[0]})")
DOCKBUILD=$(basename $DOCKDIR)
DOCKREPO=$(basename $(dirname $DOCKDIR))
DOCKTAG=${1:-"latest"}
TMPPWD=$(pwd)
indent=" "
cd $DOCKDIR
echo -e "\n ${Ctitle} Preparing files : ${Coff}${Citem}\n"
tar -cvf files.tar *.sh pre-init.d/ install.d/ | sed "s/^/${indent}↠ /"
echo -e "\n ${Ctitle} Proceed Dockerfile build : ${Coff}\n
"
docker build --force-rm -t ${DOCKREPO}/${DOCKBUILD}:${DOCKTAG} . | sed "s/^/${indent}/"
cd $TMPPWD

Binary file not shown.

View File

@ -0,0 +1,8 @@
#!/bin/bash
# @app pluie/alpine-apache
# @author a-Sansara https://git.pluie.org/pluie/docker-images
apk --update add apache2 apache2-proxy apache2-proxy-html apache-mod-fcgid libxml2 \
php5-fpm php5-cli php5-phar php5-zlib php5-zip php5-ctype php5-xml php5-pdo_mysql php5-mysqli \
php5-opcache php5-pdo php5-json php5-curl php5-gd php5-mcrypt php5-openssl php5-dom \
# php-pdo_odbc php-soap php-pgsql

View File

@ -0,0 +1,50 @@
#!/bin/bash
# @app pluie/alpine-apache
# @author a-Sansara https://git.pluie.org/pluie/docker-images
function a2setModule(){
local enable=${1:-''}
local path=${3:-'/etc/apache2/httpd.conf'}
local scom=''
local rcom='\#'
if [ ! -z $1 ] && [ ! -z "$2" ]; then
if [ "$enable" = 1 ]; then
scom='\#'
rcom=''
fi
echo "$2"
sed -i "s#${scom}LoadModule $2_module modules/mod_$2.so#${rcom}LoadModule $2_module modules/mod_$2.so#" "$path"
fi
}
ln -s /usr/lib/libxml2.so.2 /usr/lib/libxml2.so
mkdir -p /app/$WWW_DIR
mkdir /run/apache2
chown -R 1000:apache /app/$WWW_DIR
chmod -R 755 /scripts/pre-init.d
mkdir -p /run/apache2
chown apache:apache /run/apache2
tmpsed='s#^DocumentRoot ".*#DocumentRoot "/app/'$WWW_DIR'"#g'
sed -i "$tmpsed" /etc/apache2/httpd.conf
sed -i 's#AllowOverride none#AllowOverride All#' /etc/apache2/httpd.conf
initTitle "Apache" "Loading Modules"
a2setModule 1 "rewrite"
a2setModule 1 "mpm_event"
a2setModule 1 "slotmem_shm"
a2setModule 1 "heartmonitor"
a2setModule 1 "watchdog"
initTitle "Apache" "Removing Modules"
a2setModule 0 "mpm_prefork"
a2setModule 0 "proxy_fdpass" /etc/apache2/conf.d/proxy.conf
echo
tmpsed="/etc/php5/php.ini"
sed -ir 's/expose_php = On/expose_php = Off/' $tmpsed
sed -i "s|;*date.timezone =.*|date.timezone = ${TZ}|i" $tmpsed
sed -i "s|;*cgi.fix_pathinfo=.*|cgi.fix_pathinfo= 0|i" /etc/php5/php.ini
tmpsed="/etc/php5/php-fpm.conf"
sed -i "s|;*daemonize\s*=\s*yes|daemonize = no|g" $tmpsed
sed -i "s|;*listen\s*=\s*127.0.0.1:9000|listen = 9000|g" $tmpsed
sed -i "s|;*listen\s*=\s*/||g" $tmpsed
sed -i "s|pm = dynamic|pm = ondemand|g" $tmpsed
echo -e "\nIncludeOptional /app/vhost" >> /etc/apache2/httpd.conf
unset tmpsed

12
pluie/alpine-apache-fpm/main.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
# @app pluie/alpine-apache
# @author a-Sansara https://git.pluie.org/pluie/docker-images
. /scripts/common.sh
sleep 3 && \
initTitle "Starting" "Apache Daemon" && \
httpd
initTitle "Starting" "PHP-FPM"
/usr/bin/php-fpm &
tail -F /var/log/apache2/error.log

View File

@ -0,0 +1,8 @@
#!/usr/bin/bash
# @app pluie/alpine-apache
# @author a-Sansara https://git.pluie.org/pluie/docker-images
if [ ! -z "$FIX_OWNERSHIP" ] && [ "$FIX_OWNERSHIP" -eq 1 ] && [ -d /app/$WWW_DIR ]; then
chown -R 1000:apache /app/$WWW_DIR
fi
touch /var/log/apache2/error.log

View File

@ -0,0 +1,27 @@
#!/usr/bin/bash
# @app pluie/alpine-apache
# @author a-Sansara https://git.pluie.org/pluie/docker-images
if [ ! -z "/app/vhost" ]; then
cat <<EOF > "/app/vhost"
<VirtualHost *:80>
ServerName $HTTP_SERVER_NAME
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
<FilesMatch \.php$>
SetHandler proxy:fcgi://127.0.0.1:9000
</FilesMatch>
<Directory /app/$WWW_DIR>
AllowOverride None
Require all granted
DirectoryIndex $WWW_INDEX
<IfModule mod_rewrite.c>
Options -MultiViews +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ $WWW_INDEX [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
# IncludeOptional /app/vhost2
EOF
fi

View File

@ -9,7 +9,7 @@ ADD files.tar /scripts
ENV SHENV_NAME=Apache \
SHENV_COLOR=67 \
HTTP_SERVER_NAME=docker-site.dev \
HTTP_SERVER_NAME=site.docker \
WWW_DIR=www \
WWW_INDEX=index \
FIX_OWNERSHIP=1 \

View File

@ -3,6 +3,7 @@
- [index][1]
- [pluie/alpine][2] ( < 10 MB ) Alpine/3.4
- [pluie/alpine-apache][3] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24
- [pluie/alpine-apache-fpm][7] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24 Fpm
- [pluie/alpine-symfony][6] ( ~ 81 MB )
- [pluie/alpine-mysql][4] ( ~172 MB ) Mysql/5.5.47 ( MariaDB )
- [docker tips][5]
@ -78,10 +79,10 @@ for more commands :
```
$ docker exec -it apache "httpd -h"
```
[1]: https://github.com/pluie-org/docker-images
[2]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine
[3]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-mysql
[4]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache
[7]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache-fpm
[5]: https://github.com/pluie-org/docker-images/blob/master/DOCKER.md
[6]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-symfony

Binary file not shown.

View File

@ -2,7 +2,7 @@
# @app pluie/alpine-apache
# @author a-Sansara https://git.pluie.org/pluie/docker-images
apk --update add apache2 \
apk --update add apache2 apache2-proxy \
php5-apache2 php5-cli php5-phar php5-zlib php5-zip php5-ctype php5-mysqli php5-xml php5-pdo_mysql \
php5-opcache php5-pdo php5-json php5-curl php5-gd php5-mcrypt php5-openssl php5-dom \
php5-opcache php5-pdo php5-json php5-curl php5-gd php5-mcrypt php5-openssl php5-dom \
# php-pdo_odbc php-soap php-pgsql

View File

@ -10,7 +10,10 @@ chown apache:apache /run/apache2
tmpsed='s#^DocumentRoot ".*#DocumentRoot "/app/'$WWW_DIR'"#g'
sed -i "$tmpsed" /etc/apache2/httpd.conf
sed -i 's#AllowOverride none#AllowOverride All#' /etc/apache2/httpd.conf
sed -i 's#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so#\#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so#' /etc/apache2/httpd.conf
sed -i 's#\#LoadModule rewrite_module modules/mod_rewrite.so#LoadModule rewrite_module modules/mod_rewrite.so#' /etc/apache2/httpd.conf
sed -i 's#\#LoadModule mpm_event_module modules/mod_mpm_event.so#LoadModule mpm_event_module modules/mod_mpm_event.so#' /etc/apache2/httpd.conf
sed -i 's#\#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so#' /etc/apache2/httpd.conf
sed -ir 's/expose_php = On/expose_php = Off/' /etc/php5/php.ini
echo -e "\nIncludeOptional /app/vhost" >> /etc/apache2/httpd.conf
unset tmpsed

View File

@ -6,6 +6,10 @@ if [ ! -z "/app/vhost" ]; then
cat <<EOF > "/app/vhost"
<VirtualHost *:80>
ServerName $HTTP_SERVER_NAME
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
<FilesMatch \.php$>
SetHandler proxy:fcgi://127.0.0.1:9000
</FilesMatch>
<Directory /app/$WWW_DIR>
AllowOverride None
Require all granted

View File

@ -3,6 +3,7 @@
- [index][1]
- [pluie/alpine][2] ( < 10 MB ) Alpine/3.4
- [pluie/alpine-apache][3] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24
- [pluie/alpine-apache-fpm][7] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24 Fpm
- [pluie/alpine-symfony][6] ( ~ 81 MB )
- [pluie/alpine-mysql][4] ( ~172 MB ) Mysql/5.5.47 ( MariaDB )
- [docker tips][5]
@ -130,5 +131,6 @@ docker run --name mycontainer --link mysql:db ...
[2]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine
[3]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-mysql
[4]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache
[7]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache-fpm
[5]: https://github.com/pluie-org/docker-images/blob/master/DOCKER.md
[6]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-symfony

View File

@ -1,7 +1,7 @@
# @app pluie/alpine-symfony
# @author a-Sansara https://git.pluie.org/pluie/docker-images
FROM pluie/alpine-apache
FROM pluie/alpine-apache-fpm
MAINTAINER a-Sansara https://github.com/a-sansara

View File

@ -3,6 +3,7 @@
- [index][1]
- [pluie/alpine][2] ( < 10 MB ) Alpine/3.4
- [pluie/alpine-apache][3] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24
- [pluie/alpine-apache-fpm][7] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24 Fpm
- [pluie/alpine-symfony][6] ( ~ 81 MB )
- [pluie/alpine-mysql][4] ( ~172 MB ) Mysql/5.5.47 ( MariaDB )
- [docker tips][5]
@ -70,5 +71,6 @@ $ docker exec -it apache "httpd -h"
[2]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine
[3]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-mysql
[4]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache
[7]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache-fpm
[5]: https://github.com/pluie-org/docker-images/blob/master/DOCKER.md
[6]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-symfony

Binary file not shown.

View File

@ -9,5 +9,6 @@ if [ ! -d /app/$WWW_DIR ]; then
symfony new app $SYMFONY_VERSION
mv app/* /app/
chown -R 1000:apache /app/
chown -R 1000:nogroup /app/var
chmod -R g+w /app
fi

View File

@ -3,6 +3,7 @@
- [index][1]
- [pluie/alpine][2] ( < 10 MB ) Alpine/3.4
- [pluie/alpine-apache][3] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24
- [pluie/alpine-apache-fpm][7] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24 Fpm
- [pluie/alpine-symfony][6] ( ~ 81 MB )
- [pluie/alpine-mysql][4] ( ~172 MB ) Mysql/5.5.47 ( MariaDB )
- [docker tips][5]
@ -95,5 +96,6 @@ VOLUME /app
[2]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine
[3]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-mysql
[4]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache
[7]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache-fpm
[5]: https://github.com/pluie-org/docker-images/blob/master/DOCKER.md
[6]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-symfony