drupal / dockerize
Containerize a Drupal project for use as a standalone Docker/Podman container, a Docker Compose/Swarm setup, or on Kubernetes.
This package is auto-updated.
Last update: 2025-05-29 09:05:19 UTC
README
This project enables the containerization of a Drupal project for use as a standalone Docker/Podman container, a Docker Compose/Swarm setup, or on Kubernetes.
It is designed for use in remote/production environments. For local development, there're already great solutions out there.
There are also several Dockerfile alternatives for production usage (1, 2, 3). In our opinion, these alternatives are complex, highly opinionated, not suited for usage out-of-the-box or lack some of the features we provide here.
Features
- Apache +
mod_php
based. - Debian-based.
- Full project codebase included in the resulting image.
- Maximum flexibility: we try to not hardcode configuration.
- Allow to specify APT packages to install.
- Allow to specify PHP version and extensions to install in addition to Drupal required ones.
- PHP configuration is managed via environment variables. It is recommented to install drupal/settingsphp in order to manage also Drupal settings via environment variables.
What is included
Dockerfile
..env.example
.- System configuration files.
- Example Docker Compose files for local testing.
Installation
Recommended method is to use composer, since it is the same process as any other Drupal package, and allows to get updates and perform customizations with patches.
composer require drupal/dockerize
cp -a vendor/drupal/dockerize/docker .
cp docker/.env.example docker/.env
git add docker/
Alternatively you could just copy the docker/
subdirectory from this repository over your Drupal project repository and commit files.
Usage
Build options
Available build arguments:
PHP_VERSION
. Defaults to 8.3.PHP_DEFAULT_EXTENSIONS
. Default set of extensions to install. See Dockerfile for details. You can redefine it and exclude extensions.PHP_EXTRA_EXTENSIONS
. Set of extensions to install in addition to the default ones. Accepts a list such asbcmath,redis,zip
.PHP_ENVIRONMENT
. Accepted values:production
ordevelopment
. It indicates which upstreamphp.ini
file to use. Defaults toproduction
.APT_DEFAULT_PACKAGES
. Default set of system packages to install. See Dockerfile for details. You can redefine it and exclude packages.APT_EXTRA_PACKAGES
. Extra set of packages to install in addition to the default ones. Accepts a list such ascurl,jq
.
Example
docker build --build-arg PHP_EXTRA_EXTENSIONS="bcmath,redis,zip" --build-arg APT_EXTRA_PACKAGES="curl,jq" . -f docker/Dockerfile -t mydrupalsite-web
Manually build and push to a Docker registry
docker build . -f docker/Dockerfile -t registry.example.com/drupal:latest
docker push registry.example.com/drupal:latest
Local testing with docker compose
Copy and adjust .env
as needed:
cp docker/.env.example docker/.env
Build, launch and install:
docker compose -f docker/compose.yml -f docker/compose.local.yml build
docker compose -f docker/compose.yml -f docker/compose.local.yml up
docker compose -f docker/compose.yml -f docker/compose.local.yml exec drupal drush site:install --existing-config --account-pass=admin -y
Visit: http://localhost:8080
Gitlab CI
Basic example based on Auto DevOps.
include:
- template: Jobs/Build.gitlab-ci.yml
stages:
- build
build: variables:
DOCKERFILE_PATH: docker/Dockerfile
AUTO_DEVOPS_BUILD_IMAGE_EXTRA_ARGS: >-
--build-arg APT_EXTRA_PACKAGES=curl,jq
--build-arg PHP_EXTRA_EXTENSIONS=bcmath,redis,zip