This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the docker category.

Last Updated: 2021-05-16

Say you want to do something before the daemon process starts in a Docker container (e.g. seed some data, carry out some build step you're having trouble with elsewhere...)

That's where you might use an entrypoint.

For example, here's one for a WordPress container:


# NB: Remember to `chmod` the entrypoint file to be executable `chmod +x entrypoint.sh`)
set -e

install_wordpress_plugins() {
  wpcli plugin install --activate wordpress-seo
  wpcli plugin install --activate acf-content-analysis-for-yoast-seo
  wpcli plugin activate advanced-custom-fields-pro
  wpcli theme activate planetly

if [ -z "$1" ]; then

  set -- apache2-foreground "$@"

# Why `exec`? So that the final running application becomes the container's PID.
# This allows the application to receive Unix signals sent to the container.
exec "$@"

Next, the Dockerfile:

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]