Mark Riddell
Mark Riddell

Reputation: 278

Best practice for handling service configuration in docker

I want to deploy a docker application in a production environment (single host) using a docker-compose file provided by the application creator. The docker based solution is being used as a drop-in replacement for a monolithic binary installer.

The application ships with a default configuration but with an expectation that the administrator will want to apply moderate configuration changes.

There appears to be a few ways to apply custom configuration to the services that are defined in the docker-compose.yml file however I am not sure which is considered best practice. The two I am considering between at the moment are:

The first option seems the cleanest to me as the application is completely self-contained, however I would need to rebuild the image if I wanted to make any further configuration changes. The second option seems the easiest as I can make configuration changes on the fly (restarting services as required in the container).

Is there a recommended method for injecting custom configuration into Docker services?

Upvotes: 5

Views: 2130

Answers (1)

Pierre B.
Pierre B.

Reputation: 12933

Given your context, I think using a bind mount would be better.

A Docker image is supposed to be reusable in different context, and building an entire image solely for a specific configuration (i.e. environment) would defeat that purpose:

  • instead of the generic configuration provided by the base image, you create an environment-specific image
  • everytime you need to change the configuration you'll need to rebuild the entire image, whereas with a bind mount a simple restart or re-read of the configuration file by application will be sufficient
  • Docker documentation recommend that:

    Dockerfile best practice

    You are strongly encouraged to use VOLUME for any mutable and/or user-serviceable parts of your image.

    Good use cases for bind mounts

    Sharing configuration files from the host machine to containers.

Upvotes: 3

Related Questions