Initial commit

parents
sql/*.sql
www/*
!index.html
tools/*.sql
ssmtp.conf
####################################################
# HowTo Use this stack
####################################################
I / Configuration
II / Tools available ( shortcuts )
#########################################
I / Configuration
#########################################
A / Php (ssmtp)
B / Apache 2.4
C / Mysql
#------------------------------------------
A / ssmtp ( to use mail() function in php )
#------------------------------------------
Don't forget ton configure ssmtp credentials inside the file "ssmtp.conf"
cp docker/php/ssmtp.conf.dist docker/php/ssmtp.conf
vim docker/php/ssmtp
#------------------------------------------
B / Override Apache config and/or Add a vhost
#------------------------------------------
You can change the main apache config file by editing this file : "httpd.conf"
vim docker/apache/httpd.conf
To add a vhost ( virtual host ), edit the file "httpd-vhosts.conf"
vim docker/apache/httpd-vhosts.conf
#------------------------------------------
C / Override Mysql configuration
#------------------------------------------
You can add / edit all mysql options ( my.cnf ), inside this file "conf-mysql.cnf"
vim docker/mysql/conf-mysql.cnf
#########################################
II / Tools
#########################################
# cleanenv.sh :
- Remove stopped container
# logs.sh :
- show the real time logs from the container "http"
# stats.sh :
- show the ressources statistics foreach running containers
# dump_sql.sh <database name>
- Create a dump of the database <database name> inside the current directory "tools/"
# restore_sql.sh <dump file.sql>
- Restore/import the sql dump inside the SQL container .
# Adopt version 2 syntax:
# https://docs.docker.com/compose/compose-file/#/versioning
version: '2'
volumes:
database_data2:
driver: local
services:
###########################
# Setup the Apache container
###########################
# nginx:
# image: nginx:latest
# ports:
# - 7777:80
# volumes:
# - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
# volumes_from:
# - php
#
###########################
# Setup the Apache container
###########################
httpd:
container_name: dockerapache_httpd_1
restart: always
image: httpd:2.4.25
ports:
- 80:80
volumes:
- ./docker/apache/httpd.conf:/usr/local/apache2/conf/httpd.conf
#- ./docker/apache/httpd-vhosts.conf:/usr/local/apache2/conf/extra/httpd-vhosts.conf
- ./docker/apache/vhosts/:/usr/local/apache2/conf/vhosts
volumes_from:
- php
###########################
# Setup the PHP container
###########################
php:
container_name: dockerapache_php_1
restart: always
build: ./docker/php/
expose:
- 9000
volumes:
- ./www/:/usr/local/apache2/htdocs
- ./docker/php/ssmtp.conf:/etc/ssmtp/ssmtp.conf:ro
- ./docker/php/php-mail.conf:/usr/local/etc/php/conf.d/mail.ini:ro
###########################
# Setup the Database (MySQL) container
###########################
mysql:
container_name: dockerapache_mysql_1
restart: always
image: mysql:5.6.36
expose:
- 3306
volumes:
- database_data2:/var/lib/mysql
- ./docker/mysql/conf-mysql.cnf:/etc/mysql/mysql.conf.d/conf-mysql.cnf:ro
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: shop
MYSQL_USER: project
MYSQL_PASSWORD: project
This diff is collapsed.
#Default Vhost Must be the last
<VirtualHost *:80>
ServerAdmin you@example.com
ServerName localhost:80
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/usr/local/apache2/htdocs"
<Directory "/usr/local/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<FilesMatch \.php$>
# 2.4.10+ can proxy to unix socket
# SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://localhost/"
# Else we can just use a tcp socket:
SetHandler "proxy:fcgi://php:9000"
</FilesMatch>
</VirtualHost>
[mysqld]
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
server {
# Set the port to listen on and the server name
listen 80 default_server;
# Set the document root of the project
root /var/www/html;
# Set the directory index files
index index.php;
# Specify the default character set
charset utf-8;
# Setup the default location configuration
location / {
try_files $uri $uri/ /index.php;
}
# Specify the details of favicon.ico
location = /favicon.ico { access_log off; log_not_found off; }
# Specify the details of robots.txt
location = /robots.txt { access_log off; log_not_found off; }
# Specify the logging configuration
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
sendfile off;
client_max_body_size 100m;
# Specify what happens when PHP files are requested
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION_ENV development;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
# Specify what happens what .ht files are requested
location ~ /\.ht {
deny all;
}
}
FROM php:5.6-fpm
# install the PHP extensions we need
RUN set -ex; \
\
apt-get update; \
apt-get install -y \
libjpeg-dev \
libpng12-dev \
libmcrypt-dev \
ssmtp \
; \
rm -rf /var/lib/apt/lists/*; \
\
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
docker-php-ext-install gd mysqli opcache pdo_mysql json mcrypt; \
pecl install -o -f xdebug redis \
&& rm -rf /tmp/pear \
&& echo "extension=redis.so" > /usr/local/etc/php/conf.d/redis.ini \
&& echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so" > /usr/local/etc/php/conf.d/xdebug.ini;
# TODO consider removing the *-dev deps and only keeping the necessary lib* packages
# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=2'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
RUN { \
echo '[xdebug]'; \
echo 'xdebug.default_enable = 0'; \
} >> /usr/local/etc/php/conf.d/xdebug.ini
RUN { \
echo 'error_reporting = E_ALL'; \
echo 'log_errors = On'; \
echo 'display_errors = Off'; \
echo 'include_path = ".:/usr/share/php:/usr/local/apache2/htdocs/ws_engine"'; \
} > /usr/local/etc/php/php.ini
CMD ["php-fpm"]
EXPOSE 9000
[mail function]
sendmail_path = "/usr/sbin/ssmtp -t"
FromLineOverride=YES
mailhub=smtp.gmail.com:587
hostname=dockerdev.foo.net
UseSTARTTLS=YES
AuthUser=me@mydomain.net
AuthPass=mypassword
[Unit]
Description=Docker Container %I
Requires=docker.service
After=docker.service
[Service]
Restart=always
WorkingDirectory=/home/cdsl/dockerapache/
ExecStart=/usr/local/bin/docker-compose -f /home/cdsl/dockerapache/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f /home/cdsl/dockerapache/docker-compose.yml down
[Install]
WantedBy=default.target
1: Create service file inside the path : /etc/systemd/system/
vim /etc/systemd/system/docker-container@lamp_server.service
2: Reload systemctl
systemctl daemon-reload
3: Start the service
systemctl start docker-container@lamp_server.service
4: Enable the service at system startup
systemctl enable docker-container@lamp_server.service
#!/bin/bash
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(
docker ps -aq | xargs docker inspect | jq -r '.[] | .Mounts | .[] | .Name | select(.)'
) | xargs -r rm -fr
#!/usr/bin/env bash
#title :dump_sql.sh
#description :Create a sql dump for the specified database.
#author :christophe De Saint Léger
#date :20170530
#version :0.1
#usage :bash dump_sql.sh database_name
#notes :The dump will be stored inside the current directory
#==============================================================================
DATABASE=$1
docker exec dockerapache_mysql_1 /usr/bin/mysqldump --databases -uroot -psecret $DATABASE > $DATABASE.sql
#!/usr/bin/env bash
echo "grant all privileges on *.* to 'root'@'%' with grant option;"| docker exec -i dockerapache_mysql_1 /usr/bin/mysql -uroot -psecret
echo "SET GLOBAL max_allowed_packet =64 *1024 *1024" | docker exec -i dockerapache_mysql_1 /usr/bin/mysql -uroot -psecret
#!/usr/bin/env bash
#title :logs.sh
#description :Show the container logs in real time.
#author :christophe De Saint Léger
#date :20170530
#version :0.1
#usage :bash logs.sh
#notes :
#==============================================================================
docker logs --tail 100 -f dockerapache_httpd_1
#!/usr/bin/env bash
#title :restore_sql.sh
#description :Import the specified sqldump inside the mysql container.
#author :christophe De Saint Léger
#date :20170530
#version :0.1
#usage :bash restore_sql.sh database_name.sql
#notes :The sql dump must be inside the current directory
#==============================================================================
DUMP=$1
cat $DUMP | docker exec -i dockerapache_mysql_1 /usr/bin/mysql -uroot -psecret
#!/usr/bin/env bash
#title :stats.sh
#description :Show metrics of running containers
#author :christophe De Saint Léger
#date :20170530
#version :0.1
#usage :bash stats.sh
#notes :
#==============================================================================
docker stats --format "table {{.Container}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDs}}"
<h1>Hello</h1>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment