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:

# Create user
useradd myservice

# Setup config
sed -i "s/PASSWD/${SERVICE_PASSWORD}/g" /etc/myservice.conf

# Start service
exec /usr/sbin/myservice "$@"

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:


if [[ -d "$DIR" ]]; then
  /bin/run-parts --verbose "$DIR"

exec "$@"

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:

COPY /docker-entrypoint.sh
COPY /docker-entrypoint.d/* /docker-entrypoint.d/
ONBUILD COPY /docker-entrypoint.d/* /docker-entrypoint.d/
ENTRYPOINT ["/docker-entrypoint.sh", "/opt/puppetlabs/puppet/bin/mcollectived"]
CMD ["--no-daemonize"]

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


With this intensive, 2-day Docker training (Open Source, Linux based), you will understand the concepts related to Docker from development to production.


With this 2-day, comprehensive Kubernetes training, you will understand the concepts and architecture of Kubernetes (K8s) in order to use it to deploy microservice applications.

Contact us for more information!

By submitting this form, I accept that the information entered will be used for the purposes described in the privacy policy.