Sample implementation of generic templates for the Docker Init command.
Download the binary compiled for your architecture (Linux, Windows or Mac OS) from Releases.
You may rename the binary to
fake-docker, all the following samples are using this command name by default.
Using -h flag provides detail on the use of the different commands available.
Init
Init command produces Docker assets using a selected template.
$ ./fake-docker init -h
Init Command
Usage:
docker init [flags]
docker init [command]
Available Commands:
catalog Catalog Command
Flags:
-d, --directory string Local Directory containing templates to be used
-h, --help help for init
-o, --output string Local Directory to write produced files
-p, --prompt stringArray Property=Value list containing prompt values
-t, --template string Name of the template to be used
Use "docker init [command] --help" for more information about a command.Init Catalog
Init Catalog provides information relative to existing templates, reading from default inner templates folder or available in external directory
$ ./fake-docker init catalog -h
Catalog Command
Usage:
docker init catalog [flags]
Flags:
-d, --directory string Local Directory containing templates to be used
-h, --help help for catalog
-t, --template string Name of the template to get detailsDefault templates are provided in project's templates folder.
Use included alfresco template by using the -t flag:
$ ./fake-docker init -t alfresco
✔ 7.4
✔ postgres
✔ Yes
✔ Yes
✔ None
What is the name of your server?: localhostDocker assets will be produced by default in output folder:
$ tree output
output
├── README.md
├── compose.yaml
├── db
│ └── compose.yaml
├── legacy-ui
│ └── compose.yaml
├── messaging
│ └── compose.yaml
├── proxy
│ └── compose.yaml
├── repo
│ └── compose.yaml
├── search
│ └── compose.yaml
├── transform
│ └── compose.yaml
└── ui
└── compose.yamlAlfresco can be tested using a regular Docker command:
$ cd output
$ docker compose upThe project includes a sample for external templates definition in folder _samples.
Use included nginx-golang-db template from external directory by using following flags:
$ ./fake-docker init -d _samples -t nginx-golang-db
✔ postgresDocker assets will be produced by default in output folder:
$ tree output
output
├── README.md
├── backend
│ ├── Dockerfile
│ ├── go.mod
│ ├── go.sum
│ └── main.go
├── compose.yaml
├── db
│ └── password.txt
└── proxy
└── nginx.confIt can be tested using a regular Docker command:
$ cd output
$ docker compose up --buildReview generated
README.mdfile inoutputfolder for additional testing instructions.
A Docker Init template is composed by a root folder that contains a set of .tpl files. The name of the template is given by this root folder name.
Templates, with .tpl extension, can be created using text/template format.
In addition to Docker assets, a file named prompts.yaml must be located in template root folder. This file includes options to be gathered from user interaction or retrieved as command line parameters.
Every option must be specified as select or prompt according following syntax.
<id>
label: <label>
multiple: true | false
options:
- <option1>
- ...
- <optionN>For instance:
Volumes:
label: Which container volume method do you want to use?
options:
- None
- Native
- BindBy default, multiple is set to false. If more than one option is allowed to be chosen, add the multiple: true node. Selected values will be stored as a single string, separated with commas.
<id>
label: <label>
default: <value>
password: true | falseFor instance:
Server:
label: What is the name of your server?
default: localhostBy default, password is set to false. If user typing should be screened as an asterisk string, add the password: true node.
The prompt is enabled only when a boolean condition is met. The condition can include any of the previous prompts as identifier and the expression is evaluated following goval rules.
<id>
label: <label>
[options | default]: ...
condition: <value>For instance:
MessagingUser:
label: Choose the user name for your ActiveMQ user
condition: Messaging=="Yes" && MessagingCredentials=="Yes"
default: adminAs a sample, following folder hierarchy would be defining the template service:
service
├── README.md.tpl
├── compose.yaml.tpl
├── prompts.yaml
└── proxy
└── nginx.conf.tplNote that
prompts.yamlis the only file that doesn't include the template extension.tpl