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.

In dependency of the status - a template was changed or if containers are running - the menu shows possible options.

If the container is not running:

Main menu

… and after starting the container:

Main menu when the web container is running

If the database container is running you get additional items to dump/ restore databases and the mysql client.

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.22

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 [.. menu key N]]

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

     r  - remove containers     docker-compose rm -f
     s  - shutdown containers   docker-compose stop

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

     d  - Dump container database
     D  - Import Dump into container database
     M  - Open Mysql client in database container

     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'

d - Dump container database

This feature works if the database container is running.

This feature dumps the app database of the database container into ./dbdumps/ using mysqldump. The resulting sql file will be gzipped. The directory will be cleaned up: the latest 5 latest dump files will be kept.

D - Import Dump into container database

This feature works if the database container is running.

You get a file selection of the ./dbdumps/ directory. The selected sql or sql.gz file will be imported.

Hint: With this feature you can import a dump from a live system into your dev environment too. Just copy its dump into ./dbdumps/.

M - Open Mysql client in database container

With docker exec in the database container the mysql client mysql will be started with root credentials on the application database. This is faster than opening a shell on the container and start mysql -u root -p<password> <dbname> where you have to search the credentials first.

Because of the usage of docker exec it works too when the database port is not exposed.