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
rsync -av vendor/drupal/dockerize/dist/ .
git add .dockerignore docker/

Alternatively you could just copy the contents of dist/ subdirectory from this repository over your Drupal project and commit files.

Usage

Composer patches and other custom files

The Dockerfile copies assets/ subdirectory into the image. It is advised to place composer patches at assets/patches/ and any other custom files such as translations in a subdirectory of assets/.

Build options

Available build arguments:

  • GIT_COMMIT. SHA of the git commit related to this build.
  • PHP_VERSION. Defaults to 8.4.
  • 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 as bcmath,redis,zip.
  • PHP_ENVIRONMENT. Accepted values: production or development. It indicates which upstream php.ini file to use. Defaults to production.
  • 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 as curl,jq.

Example

docker build --build-arg GIT_COMMIT=$(git rev-parse HEAD)  --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:

export GIT_COMMIT=$(git rev-parse HEAD)
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 GIT_COMMIT=$CI_COMMIT_SHA
      --build-arg APT_EXTRA_PACKAGES=curl,jq
      --build-arg PHP_EXTRA_EXTENSIONS=bcmath,redis,zip

GitHub Actions

#TODO#

Supporting organizations: 
Initial development
Project maintenance (2024-2025)
Project maintenance (2025 onwards)

Project information

  • Created by jonhattan on , updated
  • shieldStable releases for this project are covered by the security advisory policy.
    Look for the shield icon below.

Releases