Be Composable

Keith edited this page Jan 7, 2019 · 3 revisions

Curiously docker-compose lacks an obvious feature - composability!

Composability is just about achievable using the .env file to set COMPOSE_FILE to a list of files. The default docker-compose.yml:docker-compose.override.yml can be replaced by a list, making docker-compose theoretically composable.

However, as usual, what docker provides in usefulness, it throws away in terms of the readability of the code used to get there. For those of us who know the value of readability, and its positive contribution to maintainability and sanity, we propose a way to solve the problem:

The simplest idea that could possibly work - a pre-processor for the docker-compose .env file.

usage:

docker-compose-use example_server.env

Docker-compose is great for publishing a set of collaborating servers, but out of the box it's only expecting one docker-compose.yml file. For anything vaguely complex that offers the users some choice it is rarely flexible enough.

The new scheme allows us to present the user with a set of options to choose from, examples, test/production/development configurations etc. And we can make docker-compose composable!

Example:

# This is an example server configuration
# .
# To use this run:
# .
# > ./docker-compose-use example_server.env
# .
# Which will turn this file into a .env file ready for
# docker-compose to use as the default set of containers
# .
# ( Lines starting with a single '# ' are removed completely. )
# ( Blanklines are removed completely. )
# ( Whitespace is trimmed. )
# ( \ continuation lines are joined. )

COMPOSE_FILE=\
    common.yml:\

    base/mariaDB.yml:\
#   base/postgres.yml:\

    phpfpm/phpfpm.yml:\

#   nginx.yml:\
    openresty.yml

resulting .env

COMPOSE_FILE=common.yml:base/mariaDB.yml:phpfpm/phpfpm.yml:openresty.yml
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.