Docker entrypoint injection

Docker containers are configured with ENTRYPOINTs, or commands that are run when the container is initialized. This can be something like the container base image’s /sbin/init or tinyinit. Sometimes however, there is a need to run something before a container’s normal entrypoint. Under Docker Compose this is as easy as injecting a command before the container entrypoint:

    entrypoint: /bin/sh
    command:
      - -c
      - |
        # f.e. cache new libs
        ldconfig

        # anything else you need to do pre-init can go here

        # the original entrypoint/command should go here
        # for example:
        /sbin/init -- /bin/supercoolprogram

I was inspired by @regbo on GitHub and their use of YAML conventions to make injecting scripts easier.

Beware image updates

If there is an update to the underlying image that changes the entrypoint, you must update your override to point to it, else the container will likely fail to start.

Left-click: follow link, Right-click: select node, Scroll: zoom
x