Skip to content
Snippets Groups Projects
Select Git revision
  • 0c31d26ad78106dc81b979e56da31c51e515105a
  • master default protected
2 results

20_Templates.md

Blame
  • user avatar
    Hahn Axel (hahn) authored
    0c31d26a
    History

    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

    :negative_squared_cross_mark: docker-compose.yml

    Main configuration for docker conposer.

    Network and servers get a application name as prefix.

    :negative_squared_cross_mark: It is not needed to change this file.

    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
    

    :negative_squared_cross_mark: dot_env

    The template for .env of docker composer.

    :negative_squared_cross_mark: It is not needed to change this file.

    # 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}}

    :negative_squared_cross_mark: 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.

    :negative_squared_cross_mark: It is not needed to change this file.

    # 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}}

    :exclamation:vhost_app.conf

    Apache vhost configuration for your app.

    :exclamation:It's a MUST to change this file.

    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>

    :eight_pointed_black_star: extra-php-config.ini

    Custom PHP config file for you additional settings. Showing all warnings and errors is enabled as default.

    :eight_pointed_black_star: You SHOULD change this to setup Mysql database service for your needs.

    # 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"

    :eight_pointed_black_star: my.cnf

    If you use a Mariadb a 2nd container will be initialized using this my.cnf.

    :eight_pointed_black_star: You SHOULD change this to setup Mysql database service for your needs.

    # TARGET: docker/containers/db-server/mariadb/my.cnf
    [mysqld]
    ; collation-server = utf8mb4_unicode_ci
    ; character-set-server = utf8mb4