title: Best practice for handling service configuration in docker
body: <p>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.</p>
  
  <p>The application ships with a default configuration but with an expectation that the administrator will want to apply moderate configuration changes.</p>
  
  <p>There appears to be a few ways to apply custom configuration to the services that are defined in the <code>docker-compose.yml</code> file however I am not sure which is considered best practice. The two I am considering between at the moment are:</p>
  
  <ul>
  <li><p><strong>Bake the configuration into a new image</strong>. Here, I would add a build step for each service defined in the docker-compose file and create a minimal <code>Dockerfile</code> which uses <code>COPY</code> to replace the existing configuration files in the image with my custom config files. Using <code>sed</code> and <code>echo</code> in <code>CMD</code> statements could also be used to change configuration inline without replacing the files wholesale.</p></li>
  <li><p><strong>Use a bind mount with configuration stored on the host</strong>. In this case, I would store all custom configuration files in a directory on the host machine and define bind mounts in the <code>volumes</code> parameter for each service in the docker-compose file.</p></li>
  </ul>
  
  <p>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).</p>
  
  <p>Is there a recommended method for injecting custom configuration into Docker services?</p>