Use docker init script

Interactive mode

If you simply start the init.sh then you get an interactive mode. There is a menu offerning a key and the description for its action. If an action is finished you get the menu again.

Main menu

Command line parameters

The script supports command line parameters to use it in scripts. Use -h to get a help:

INITIALIZER FOR DOCKER APP v1.10

A helper script written in Bash to bring up a PHP+Mysql application in docker.

Source : https://git-repo.iml.unibe.ch/iml-open-source/docker-php-starterkit
Docs   : https://os-docs.iml.unibe.ch/docker-php-starterkit/
License: GNU GPL 3.0
(c) Institute for Medical Education; University of Bern


SYNTAX:
  init.sh [-h|-v]
  init.sh [menu key]

OPTIONS:
  -h   show this help and exit
  -v   show version exit

MENU KEYS:
  In the interactive menu are some keys to init an action.
  The same keys can be put as parameter to start this action.
  You can add multiples keys to apply multiple actions.

   g  - remove git data of starterkit

   i  - init application: set permissions
   t  - generate files from templates
   T  - remove generated files

   u  - startup containers    docker-compose ... up -d
   U  - startup containers    docker-compose ... up -d --build
   s  - shutdown containers   docker-compose stop
   r  - remove containers     docker-compose rm -f

   m  - more infos
   o  - open app [my_new_app] http://localhost:8001/
   c  - console (bash)
   p  - console check with php linter

   q  - quit

EXAMPLES:

  init.sh           starts interactive mode
  init.sh u         bring up docker container(s) and stay in interactive mode
  init.sh i q       set write permissions and quit
  init.sh p q       start php linter and exit

Actions

g - remove git data of starterkit

After cloning the starter kit repo for a new project you don’t want to commit project data to the starter kit but to your project. This feature removes the git directory if it is connected with the starter kit repository. If you initialized another project it will bedetected and this feature does nothing.

i - init application: set permissions

On a rootless docker setup you need to set the write permission for the www-data user and your current desktop user.

t - generate files from templates

Insite the docker/templates directory are templates.

Rules:

  • in the first line must be a line # TARGET: [name of target file] to define the target file
  • Placeholdrs have the syntax variable in double brackets, i.e. {{VARNAME}}
  • variables to be replaced are those in docker/init.sh.cfg and {{genrator}}

This feature generates the files from the templates and puts them in the correct place.

T - remove generated files

This feature removes the files generated by the t action.

u - startup containers docker-compose … up -d

Fast start webserver container and database container (if enabled).

U - startup containers docker-compose … up -d –build

Build and start webserver container and database container (if enabled).

s - shutdown containers docker-compose stop

Shut down your containers.

r - remove containers docker-compose rm -f

Remove your containers.

m - more infos

Show processes.

o - open app [my_new_app] http://localhost:NNNN/

Start a browser and open the application. This feature uses the command xdg-open to run on Linux.

c - console (bash)

Open a console and start a Bash inside webserver container.

If you have a database container too then you get a selection for the first.

You need to type exit and press Return to return to the menu.

p - console check with php linter

Start a docker command on the webserver container and start php lint for all php files:

find . -name '*.php' -exec php -l {} \; | grep -v '^No syntax errors detected'

Starting from PHP 8.3 php -l supports multiple files. A newer PHP version will be detected to use the faster mode automatically:

php -l $( find . -name '*.php' ) | grep -v '^No syntax errors detected'