docker-compose template

Run it

Execute this template like so:

cookiecutter https://quico.space/Quico/py-cookiecutter-templates.git --directory 'docker-compose'

Cookiecutter interactively prompts you for the following info, here with example answers:

service []: grafana
component_list [grafana]: grafana,nginx
context []: cncf

Done, directory structure and files for your next docker-compose project are ready for you to hit the ground running.

Explanation and terminology

Each docker-compose project forms a service that may consist of either a single or multiple components.

The service variable by default is empty. In this example we've chosen to name the service grafana. We want grafana to consist of two components, namely Grafana itself and Nginx. Syntax for a multi-component component_list is a comma-separated list without spaces. The string grafana,nginx will be treated as a list of two components. Capitalization doesn't matter, we're lowercasing all strings automatically. The template prefills component_list with whatever you previously entered as the service name. To create directory structure for a single-component service confirm the default. If component_list and service are identical directory structure will be that for a single-component service.

The last prompt for a context is a generic string to help you distinguish deployments. It can be whatever you want such as for example a team name, here cncf.

Result

Multi-component service

Above example of a multi-component (two in this case) grafana service will give you this directory structure:

.
└── grafana
    ├── build-context
    │   ├── grafana
    │   │   ├── docker-data
    │   │   │   └── .gitkeep
    │   │   ├── Dockerfile
    │   │   └── extras
    │   │       └── .gitkeep
    │   └── nginx
    │       ├── docker-data
    │       │   └── .gitkeep
    │       ├── Dockerfile
    │       └── extras
    │           └── .gitkeep
    ├── common-settings.yml
    ├── docker-compose.override.yml
    ├── docker-compose.yml
    └── env
        └── fully.qualified.domain.name.example

Check out file contents over in the examples/grafana subdir.

Single-component service

With an alternative single-component hashicorpvault service the result may look like this:

.
└── hashicorpvault
    ├── build-context
    │   ├── docker-data
    │   │   └── .gitkeep
    │   ├── Dockerfile
    │   └── extras
    │       └── .gitkeep
    ├── common-settings.yml
    ├── docker-compose.override.yml
    ├── docker-compose.yml
    └── env
        └── fully.qualified.domain.name.example

Check out file contents over in the examples/hashicorpvault subdir.