This Dockerfile creates a Docker image for a Drupal application with Drush and Postgres support. It is based on the official Drupal image and includes additional configurations and extensions to support a more robust Drupal development environment.
DockerHub cloudgrounds/drupal-postgres
- Based on
drupal:10.2.6-php8.2-apache-bookworm
image from the official Drupal image - Includes Drush, a command-line shell and scripting interface for Drupal
- Configured to use Postgres as the database
- Includes APCu PHP extension for caching
- Configures PHP for output buffering
- Sets up default Drupal settings and file permissions
To build the Docker image, navigate to the directory containing the Dockerfile and run:
docker build -t your-custom-image:1.0 .
To run drupal from the image use docker compose
with the example file
HASH_SALT=yourreallyreallylongandrandomhash DRUPAL_ADMIN_PASS=yourfirstsupersafepassword POSTGRES_PASSWORD=yourothersupersafepassword docker-compose up -d
The Dockerfile uses the following environment variables:
POSTGRES_DB
: The name of your Postgres databasePOSTGRES_USER
: The username for your Postgres databasePOSTGRES_PASSWORD
: The password for your Postgres databasePOSTGRES_HOST
: The host of your Postgres databaseDRUPAL_HASH_SALT
: The hash salt for your Drupal applicationDRUPAL_CONFIG_SYNC_DIRECTORY
: The directory for Drupal configuration synchronization files. This should be outside web root. This defaults to/var/configsync
DRUPAL_ADMIN_USER
: The username for your Drupal admin accountDRUPAL_ADMIN_PASS
: The password for your Drupal admin accountDRUPAL_ADMIN_EMAIL
: The email for your Drupal admin account
The Dockerfile specifies volumes for the Drupal installation and files directories. This allows you to persist data across container restarts and share data between containers. See the Volumes section in the official Drupal image.
The entrypoint.sh
script is executed when the Docker container starts. It performs several checks and operations to ensure the Drupal site is properly set up.
The script performs the following operations:
- Checks the status of the database connection and Drupal bootstrap using Drush.
- If the database is not connected and Drupal is not bootstrapped, it installs the Drupal site using the
drush site-install
command. - If the database is connected or Drupal is bootstrapped, it updates the database using the
drush updatedb
command and rebuilds the cache using thedrush cache-rebuild
command. - Finally, it executes the command passed to the
docker run
command.
Environment variables are included above and should be set in your Docker environment or in your docker-compose.yml
file.
Drush is a command-line shell and Unix scripting interface for Drupal. Drush core ships with lots of useful commands for interacting with code like modules/themes/profiles. Similarly, it runs update.php, executes SQL queries and DB migrations, and misc utilities like run cron or clear cache.
For more information about the Drush commands used in this script, see the following links:
By default, the Docker container will run Apache in the foreground.
Versions are based on the run number in the GitHub Actions publication workflow.