docker-entrypoint-initdb.d

The docker-entrypoint-initdb.d directory is used to store shell or SQL scripts that you want to be executed when a Docker container is started for the first time. Here are some key points:

  1. Initialization: When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables.

  2. Script Execution: It will execute files with extensions .sh, .sql and .sql that are found in /docker-entrypoint-initdb.d. The scripts inside that directory will only get executed once - when initializing a fresh instance.

  3. Order of Execution: The /docker-entrypoint-initdb.d/init.sql is executed the moment your database container starts running, while your entrypoint.sh is executed the moment your web container starts running. Since your web container depends on your database container, the SQL script will always be executed ahead of your entrypoint.

This feature is particularly useful in scenarios where you need to initialize your database with certain data or configurations before your application starts running. For example, you might want to create necessary users, tables, etc., in a PostgreSQL docker container.