0atman
0atman

Reputation: 3384

Centralised configuration of docker-compose services

Imagine a non-trivial docker compose app, with nginx in front of a webapp, and a few linked data stores:

web:
  build: my-django-app
  volumes:
    - .:/code
  ports:
    - "8000:8000"
  links:
    - redis
    - mysql
    - mongodb
nginx:
  image: nginx
  links:
    - web
redis:
  image: redis
  expose:
    - "6379"
mysql:
  image: mysql
  volumes:
    - /var/lib/mysql
  environment:
    - MYSQL_ALLOW_EMPTY_PASSWORD=yes
    - MYSQL_DATABASE=myproject
mongodb:
  image: mongo

The databases are pretty easy to configure (for now), the containers expose pretty nice environmental variables to control them (see the mysql container), but what of nginx? We'll need to template a vhost file for that, right?

I don't want to roll my own image, that'll need rebuilding for each changed config, from different devs' setups, to test, through staging and production. And what if we want to, in a lightweight manner, do A/B testing by flipping a config option?

Some centralised config management is needed here, maybe something controlled by docker-compose that can write out config files to a shared volume?

This will only get more important as new services are added (imagine a microservice cloud, rather than, as in this example, a monolithic web app)

What is the correct way to manage configuration in a docker-compose project?

Upvotes: 3

Views: 470

Answers (1)

Adrian Mouat
Adrian Mouat

Reputation: 46500

In general you'll find that most containers use entrypoint scripts to configure applications by populating configuration files using environment variables. For an advanced example of this approach see the entrypoint script for the Wordpress official image.

Because this is a common pattern, Jason Wilder created the dockerize project to help automate the process.

Upvotes: 3

Related Questions