Templating¶
If anything is confusing, unclear, missing, or maybe even wrong on this page, then please let us know by submitting a bug report
The Docker container can do some basic templating (more like variable replacement) as part of the entrypoint scripts via gomplate.
Any file in the /docker/templates/
directory will be templated and written to the proper directory.
File path examples¶
- To template
/usr/local/etc/php/php.ini
in the container, put the source file in/docker/templates/usr/local/etc/php/php.ini
. - To template
/a/fantastic/example.txt
in the container put the source file in/docker/templates/a/fantastic/example.txt
. - To template
/some/path/anywhere
in the container, put the source file in/docker/templates/some/path/anywhere
.
Available variables¶
Variables available for templating are sourced (in order, so last source takes precedence) like this:
env:
in yourdocker-compose.yml
or-e
in yourdocker run
/docker compose run
commands.- Any exported variables in
.envsh
files loaded before05-templating.sh
(e.g., any file with04-
,03-
,02-
,01-
or00-
prefix). - All key and value pairs in
/var/www/.env.docker
(default values, you should not edit this file!) - All key and value pairs in
/var/www/.env
.
Template guide 101¶
Please see the gomplate
documentation for a comprehensive overview.
The most frequent use case you have is likely to print an environment variable (or a default value if it's missing), so this is how to do that:
{{ getenv "VAR_NAME" }}
print an environment variable and fail if the variable is not set. (docs){{ getenv "VAR_NAME" "default" }}
print an environment variable and printdefault
if the variable is not set. (docs)
The script will fail if you reference a variable that does not exist (and doesn't have a default value) in a template.
Please see the