20_Templates.md
Basic rules
- Do not start with the Teplates! Edit the init.sh.cfg first to define placeholders and variables.
- All files in the
docker/templates/
directory will be processed. This also means: you can add as many custom files here as you want - and the will processed too. - in the first line must be a line
# TARGET: [name of target file]
to define the target file. If this line does not exist, then the file will be skipped. - Placeholdrs have the syntax variable in double brackets, i.e.
{{VARNAME}}
- variables to be replaced are those in docker/init.sh.cfg and
{{genrator}}
Templates

docker-compose.yml

Main configuration for docker conposer.
Network and servers get a application name as prefix.
Optional changes:
- if you have more directories than webroot add a mount in the volumes section
# TARGET: docker/docker-compose.yml
#
# {{generator}}
#
# ======================================================================
#
# (1) see .env for set variables
# (2) run "docker-compose up" to startup
#
# ======================================================================
version: '3.9'
networks:
{{APP_NAME}}-network:
services:
# ----- apache httpd + php
{{APP_NAME}}-web-server:
build:
context: .
dockerfile: ./containers/web-server/Dockerfile
image: "php:{{APP_PHP_VERSION}}-apache"
container_name: '{{APP_NAME}}-server'
ports:
- '${APP_PORT}:80'
working_dir: ${WEBROOT}
volumes:
- ../:/var/www/${APP_NAME}
- ./containers/web-server/apache/sites-enabled:/etc/apache2/sites-enabled
- ./containers/web-server/php/extra-php-config.ini:/usr/local/etc/php/conf.d/extra-php-config.ini
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 10s
timeout: 3s
retries: 5
# start_period: 40s
networks:
- {{APP_NAME}}-network
user: ${DOCKER_USER_UID}
# --- 8< --- {{CUTTER_NO_DATABASE}} --- 8< ---
depends_on:
- {{APP_NAME}}-db-server
# ----- mariadb
{{APP_NAME}}-db-server:
image: {{MYSQL_IMAGE}}
container_name: '${APP_NAME}-db'
# restart: always
ports:
- '${DB_PORT}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${MYSQL_ROOT_PASS}'
MYSQL_USER: '${MYSQL_USER}'
MYSQL_PASSWORD: '${MYSQL_PASS}'
MYSQL_DATABASE: '${MYSQL_DB}'
volumes:
# - ./containers/db-server/db_data:/var/lib/mysql
- ./containers/db-server/mariadb/my.cnf:/etc/mysql/conf.d/my.cnf
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u root --password=$$MYSQL_ROOT_PASSWORD
interval: 5s
retries: 5
networks:
- {{APP_NAME}}-network

dot_env

The template for .env
of docker composer.
# TARGET: docker/.env
# ======================================================================
#
# {{generator}}
# values to be used in docker-composer.yml
#
# ======================================================================
# ----- application
APP_NAME={{APP_NAME}}
# uid of www-data in the docker container
DOCKER_USER_UID={{DOCKER_USER_UID}}
APP_PORT={{APP_PORT}}
WEBROOT={{WEBROOT}}
# --- 8< --- {{CUTTER_NO_DATABASE}} --- 8< ---
DB_PORT={{DB_PORT}}
# ----- database settings
MYSQL_RANDOM_ROOT_PASSWORD={{MYSQL_RANDOM_ROOT_PASSWORD}}
MYSQL_ALLOW_EMPTY_PASSWORD={{MYSQL_ALLOW_EMPTY_PASSWORD}}
MYSQL_ROOT_PASS={{MYSQL_ROOT_PASS}}
MYSQL_USER={{APP_NAME}}
MYSQL_PASS={{MYSQL_PASS}}
MYSQL_DB={{APP_NAME}}

Webserver-Dockerfile

Docker container file for Apache httpd and PHP. It uses the oficial PHP docker images by default. It installes given packages and php modules. To override default module settings see template with "extra-php-config.ini" below.
# TARGET: docker/containers/web-server/Dockerfile
#
# {{generator}}
#
FROM php:{{APP_PHP_VERSION}}-apache
# install packages
RUN apt-get update && apt-get install -y {{APP_APT_PACKAGES}}
# enable apache modules
RUN a2enmod {{APP_APACHE_MODULES}}
# install php packages
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions {{APP_PHP_MODULES}}

vhost_app.conf

Apache vhost configuration for your app.
Setup modules and the vhost including rewrites , ...
# TARGET: docker/containers/web-server/apache/sites-enabled/vhost_app.conf
#
# {{generator}}
#
<VirtualHost *:80>
DocumentRoot {{WEBROOT}}
<Directory {{WEBROOT}}>
AllowOverride None
Order Allow,Deny
Allow from All
</Directory>
# example to prevent access with http
<Location "/no-access">
Require all denied
</Location>
</VirtualHost>

extra-php-config.ini

Custom PHP config file for you additional settings. Showing all warnings and errors is enabled as default.
# TARGET: docker/containers/web-server/php/extra-php-config.ini
;
; {{generator}}
;
[PHP]
error_reporting=E_ALL
display_errors=1
; ----------------------------------------------------------------------
; XDEBUG STUFF BELOW
; ----------------------------------------------------------------------
;
; error_reporting=E_ALL
;
; [xdebug]
; xdebug.mode=develop,debug
; ; xdebug.client_host=localhost
; xdebug.start_with_request=yes
; ; xdebug.start_with_request=trigger
;
; xdebug.log=/tmp/xdebug.log
; xdebug.discover_client_host = 1
; ; xdebug.client_port=9003
; xdebug.idekey="netbeans-xdebug"

my.cnf

If you use a Mariadb a 2nd container will be initialized using this my.cnf.
# TARGET: docker/containers/db-server/mariadb/my.cnf
[mysqld]
; collation-server = utf8mb4_unicode_ci
; character-set-server = utf8mb4