Infrastructure – News

Flexible Docker entrypoints scripts

22 March 2016

When a Docker container starts, it calls its entrypoint command. Most of the time, this is the path to the service that should run in that container. It is however very common to run wrapping scripts in order to configure the container before starting the service:

Very often, this is achieved with a monolithic entrypoint script containing all the tuning options required for the container. This has several drawbacks:

  • inherited images need to fork that script in order to add tuning
  • the script is hard to maintain and cluttered
  • the script is written in one language (usually shell script)

At Camptocamp, while working on our Dockerized Puppet stack on Rancher, we have chosen to take a more flexible approach to entrypoint scripts by using a standard, static entrypoint script calling run-parts on a directory:

This brings us various advantages:

  • the entrypoint script is a standard in all our containers
  • entrypoint scripts are plugins that can be written in any language
  • inherited images can add to existing entrypoint scripts by simply adding to the /docker-entrypoint.d/ directory

Our Dockerfiles usually contain ONBUILD COPY statements to ease the deployment of additional entrypoint scripts. We can then set the entrypoint to call that generic script with the path to the service that needs to run, for example:

Various examples of entrypoint scripts can be found in our Docker projects.