Search by

lakedrops / docker4drupal

jurgenhaas

Composer Plugin to prepare local Drupal development environment for Docker.

Package info

gitlab.lakedrops.com/composer/plugin/docker4drupal

Issues

Documentation

Type:composer-plugin

pkg:composer/lakedrops/docker4drupal

Statistics

Installs: 52 213

Dependents: 3

Suggesters: 0

v3.10.112 2026-11-21 15:47 UTC

This package is auto-updated.

Last update: 2026-11-24 12:20:23 UTC


README

Composer plugin that renders Docker Compose services for Drupal projects.

Public and private service domains

DOCKER4DRUPAL_TRAEFIK_PRIVATE_DOMAIN affects CI builds only, including Build Prod Site NG (LAKEDROPS_BUILD_NG=yes). When set, auxiliary services use <service>-<project>.<private domain>. The Drupal web server retains its configured project domain. Local development and L3D sandboxes ignore the private domain variable.

Invoice Ninja always stays public in Build Prod Site NG, including staging stacks built by that job. Its router and APP_URL both use invoice-<public project domain>, preserving the URL from before v3.10.98. For example, invoice-main-example.example.com does not change when a runner adds a private domain. Other auxiliary services remain private. The public project domain comes from the existing project configuration; this change does not construct a different public hostname or add a second router.

Non-production pipeline previews still use the private domain for Invoice Ninja, including their container host mappings. They are test environments, not the customer-facing production application.

This is an explicit, non-configurable exception: servicedomain holds the shared auxiliary domain, while the computed invoicedomain holds Invoice Ninja's domain. A configurable per-service exposure switch would let a project accidentally violate the requirement that customer-facing Invoice Ninja stays public.

OpenTelemetry endpoint address

DOCKER4DRUPAL_OPENTELEMETRY_ADDRESS is the IPv4 address that the php container uses for the host of OPENTELEMETRY_ENDPOINT, the OTLP endpoint that lakedrops/drupal-environment configures for the drupal/opentelemetry module. It is meant for a log server that admits NetBird peers only while its name still resolves to a public address, for example DOCKER4DRUPAL_OPENTELEMETRY_ADDRESS=100.64.104.21 with OPENTELEMETRY_ENDPOINT=https://logs.lakedrops.com/api/default. php then gets the entry logs.lakedrops.com:100.64.104.21 in its extra_hosts, in the same list as the names of LOCAL_IP and the private domain.

The mapping applies to pipeline builds, Build Prod Site NG, and local development, where L3D exports the variables of ~/.env and the project's .env. L3D sandboxes ignore it. Without the variable, or without a host in OPENTELEMETRY_ENDPOINT, nothing changes. An address that is not IPv4 is ignored with a warning.

The log server's own host. There, a request from a container to one of the host's addresses arrives at Traefik from the gateway of traefik-public, which Traefik refuses for NetBird-only names. A pipeline build recognizes this host when the variable equals the runner's DOCKER4DRUPAL_TRAEFIK_NETBIRD_ADDRESS: php joins traefik-public and maps the endpoint's host to Traefik's address there, never to the gateway. As with the private domain, gw_priority: 1 on the project's default network of php and the web server keeps service names such as php resolving to the own project once a php of another project joins traefik-public. This needs Docker 28 and Compose 2.33 or later. The web servers of stacks rendered without it on the same host, by older releases of this plugin or without these variables, have no such priority.

Build Prod Site NG always uses the address as given. DeployNG writes the gateway of traefik-public, not Traefik's address, for TRAEFIK-IP-PLACEHOLDER, so live and staging stacks on the log server's own host cannot reach a NetBird-only endpoint there. Such stacks are not supported.

Invoice Ninja database

in-db runs MariaDB 12.3 LTS (supported until June 2029) and keeps its data in in/mariadb. Versions up to 3.10.100 used MySQL 5.7 with data in in/db. Invoice Ninja 5.13 needs window functions and REGEXP_REPLACE, and Laravel's database queue uses SKIP LOCKED only on MySQL 8.0.1 or later and MariaDB 10.6 or later; without it, queue workers deadlock on the jobs table.

Its healthcheck pings the server over TCP with the root password from the container's environment, not with the image's healthcheck.sh. In pipeline workspaces with default ACLs, the image's .my-healthcheck.cnf becomes world-writable, so the client ignores it and healthcheck.sh fails with Access denied. TCP also keeps the temporary server of the initialization, which runs without networking, from counting as healthy.

The new release does not read in/db. An existing project starts with an empty Invoice Ninja database until its data is migrated; in/db stays untouched as the rollback copy. To migrate, replacing <root password> with the MYSQL_ROOT_PASSWORD of in-db:

  1. With the old stack running, stop in-app (docker compose stop in-app), then dump the database:

    docker compose exec -T in-db mysqldump -u root -p'<root password>' \
      --single-transaction --routines --triggers --hex-blob \
      --default-character-set=utf8mb4 ninja > ninja.sql
    
  2. Update the plugin and regenerate docker-compose.yml.

  3. Start only the database, wait until docker compose ps in-db reports it healthy, then import the dump:

    docker compose up -d in-db
    docker compose exec -T in-db mariadb -u root -p'<root password>' ninja < ninja.sql
    
  4. Start the remaining services with docker compose up -d; in-app runs its migrations on startup.

  5. Verify Invoice Ninja, then remove in/db.

Deployments that start all services at once, such as Build Prod Site NG, give no chance to import between steps 3 and 4. Pre-seed in/mariadb before deploying instead: run a temporary container with the same image, environment, command, and data mount as in-db, import the dump there, and stop it cleanly.

Production jobs install the newest release, so migrate each Invoice Ninja production stack in the same window as the deployment that picks up this release.

Jobs that no worker takes pile up unnoticed. Invoice Ninja queues its jobs in the jobs table of ninja. From the project directory, list per queue the jobs that have waited or been reserved for more than an hour, and how many of them are reserved:

docker compose exec -T in-db sh -c 'MYSQL_PWD="$MYSQL_ROOT_PASSWORD" mariadb -u root -N -e "select queue, count(*), sum(reserved_at is not null) from jobs where coalesce(reserved_at, available_at) < unix_timestamp() - 3600 group by queue" ninja'

It returns no rows. Reserved rows are stuck: on MySQL 5.7, a worker's delete after a finished job often deadlocked and left the row reserved, so their jobs have run. Rows that are not reserved wait on a queue that no worker takes: the workers of the image run queue:work without --queue and take only default. Invoice Ninja 5.12.18 (upstream 7af38fc) put every Laravel\Scout\Jobs\MakeSearchable job on queue scout; since upstream 1cef467 it queues them only when SCOUT_DRIVER is set, which in-app does not do, so projects that ran a release in between hold such rows. With Scout's null driver they do nothing when run. Back up the rows of such a queue, then delete them, here for scout:

docker compose exec -T in-db sh -c 'MYSQL_PWD="$MYSQL_ROOT_PASSWORD" mariadb-dump -u root --no-create-info --where="queue='\''scout'\''" ninja jobs' > jobs-scout.sql
docker compose exec -T in-db sh -c 'MYSQL_PWD="$MYSQL_ROOT_PASSWORD" mariadb -u root -e "delete from jobs where queue = '\''scout'\''" ninja'

AI agent settings

The plugin writes no AI agent settings by default. When enabled, it writes .claude/mcp.json, .ai/template.md, and .ai/prepare.md, and adds /.claude/ to .gitignore; ahoy d4d aiprepare then shows how to prepare AGENTS.md with them. Enable it for a project in .lakedrops.yml:

docker4drupal:
  ai:
    enable: 1

The same key in .lakedrops.user.yml enables it for one developer only. Alternatively, set DOCKER4DRUPAL_AI=1 in the project's .env, where the plugin records the default DOCKER4DRUPAL_AI=0 on its first run. Then run ahoy d4d update.

Projects that already have these files keep them: without the setting, the plugin only stops writing them. Remove them, and the /.claude/ entry in .gitignore, manually if they are no longer wanted.

Mail relay

The optional mailrelay service is a Postfix null client (boky/postfix v5.2.1) that queues the mail of a live site. Without it, Drupal sends each mail synchronously to the provider's SMTP server with a single attempt, so a stalled provider hangs the request and loses the mail. With the relay, Drupal hands the mail over on the internal network within milliseconds. Postfix queues it, retries the first time after about 5 minutes, and gives up and bounces it after 5 days.

Config keys of the docker4drupal component, below mailrelay:

KeyDefaultEnvironment variablePurpose
enable0noneRenders the relay.
host''MAILRELAY_HOSTThe provider's SMTP host.
port587MAILRELAY_PORTThe provider's SMTP port.
username''MAILRELAY_USERNAMEThe provider's username; empty sends without credentials.
password''MAILRELAY_PASSWORDThe provider's password.
senderdomains''MAILRELAY_SENDER_DOMAINSSpace-separated sender domains; required by the image.
hostname''noneThe relay's Postfix hostname; empty derives it.
concurrency2noneMaximum parallel connections to the provider.

Keep the credentials in CI/CD variables, never in .lakedrops.yml. The plugin never prompts for these variables and, like other variables, records their defaults in the project's .env on its first run. Enable the relay for the live stage in .lakedrops.yml:

stage_overwrites:
  main:
    docker4drupal:
      mailrelay:
        enable: 1
        host: smtp.example.com
        senderdomains: example.com

Mailpit wins. With mailpit.enable, the relay is not rendered at all, so a stage with Mailpit never delivers mail for real. A project may therefore enable the relay for all stages; only the stages without Mailpit, such as main in Build Prod Site NG, use it.

With the relay enabled, the plugin renders:

  • The mailrelay service on the project's default network only, without a Traefik router, with restart: unless-stopped on live sites. Its queue is the mailrelay/ directory below the project root, in Build Prod Site NG /drupal/<project id>/<branch>/mailrelay, and survives recreated containers. The plugin adds /mailrelay/ to .gitignore.
  • In php, a depends_on entry for mailrelay and PHP_SENDMAIL_PATH=/usr/sbin/sendmail -t -i -S mailrelay:587. The condition is service_started, not service_healthy: a misconfigured relay must never keep php, and with it the site, from starting. Postfix needs about 12 seconds to start, so mail sent in the first seconds after the stack starts fails.
  • In settings.docker.php, the mailer_dsn of system.mail, the smtp.settings, and the smtp transport of symfony_mailer_lite plus its default transport, all pointing at mailrelay:587 without credentials. The site's mail system stays as configured.

TLS. The relay sends to [host]:port; the brackets skip the MX lookup. STARTTLS to the provider is required. The relay offers no STARTTLS to Drupal: Symfony's ESMTP transport would upgrade the connection and then fail verify_peer against the image's self-signed certificate. Unencrypted mail only crosses the project's internal network.

Trusted clients. The relay sets POSTFIX_mynetworks=0.0.0.0/0,[::]/0 and accepts mail from every client that reaches it: it joins only the project's default network and publishes no port, so that network is the trust boundary. The image's default list trusts only the RFC 1918 ranges and rejects php on Docker hosts whose address pools lie outside them, such as 169.254.0.0/16. ALLOWED_SENDER_DOMAINS still limits the senders.

Hostname. The relay sets POSTFIX_myhostname to mailrelay.hostname, or, if that is empty, to the project's publicdomain, or, without one, to its projectdomain. Postfix uses this name in EHLO, in its Received: header, and as the sender of MAILER-DAEMON bounces. Without it, the image would use the container ID, which is no fully qualified domain name and changes with every deploy. The image keeps mydestination empty, so a domain in the hostname never makes Postfix deliver mail for it locally.

Concurrency. The relay sets POSTFIX_smtp_destination_concurrency_limit to mailrelay.concurrency, 2 by default. Postfix's own default, 5 at first and up to 20, opens several parallel connections to the one smarthost during a burst. Shared hosting providers cap the connections per client and refuse the extra ones with 421 too many connections, which defers that mail by one retry interval of about 5 minutes. Two connections still deliver a burst within seconds, because Postfix reuses open connections. Raise the value if the provider allows more connections.

Further Postfix settings, such as POSTFIX_minimal_backoff_time or ANONYMIZE_EMAILS, go into the docker-compose.yml key of .lakedrops.yml below services: mailrelay: environment:. Add new keys only: the merge turns an existing key into a list.

Consequences. Drupal no longer sees delivery failures. Watch docker compose logs mailrelay for status=deferred and status=bounced. Permanent rejections bounce to the envelope sender. The logs contain recipient addresses. docker compose exec mailrelay mailq lists the queue, and docker compose exec mailrelay postqueue -f flushes it.

Site URL

The php service gets DRUPAL_URI, the site's URL, in local development, pipelines and on live sites alike. Drupal core's CLI, vendor/bin/dr, has no config file: it takes the URL from --url, then from DRUPAL_URI, and falls back to http://localhost. Cron jobs run in php and inherit the variable.

With a publicdomain, the value is https://<publicdomain>: Traefik redirects the project domain there, always over https. Otherwise it is <projectprotocol>://<projectdomain><projectport>, the URL that drush.yml gives Drush as options.uri, for example http://example.docker.localhost:8000 in local development without SSL. Build Prod Site NG sets https and no port.

Tests

Install dependencies without activating Composer plugins in this plugin's own checkout, then run the integration test:

composer install --no-interaction --no-scripts --no-plugins
composer --no-plugins test
composer --no-plugins validate --no-check-publish
for file in src/*.php tests/*.php; do php -l "$file" || exit; done

On an L3D host, run these commands through l3d .. The test uses the real configuration class and Twig template, parses the generated YAML, and checks production with and without a private domain, production staging, pipeline previews, local development, and sandboxes. It checks the Invoice Ninja router and APP_URL together, other auxiliary routes, and pipeline host mappings. In the same contexts, it checks that in-db runs MariaDB with a healthcheck that pings over TCP without healthcheck.sh, keeps its data in in/mariadb, never in/db, and that in-app waits for a healthy in-db. For DOCKER4DRUPAL_OPENTELEMETRY_ADDRESS, it checks the entry and the networks of php in each of these contexts, on the log server's own host and on another one, and that the file stays the same without the variable, without a host in the endpoint, or with an address that is not IPv4. For the mail relay, it checks the service, the derivation of its hostname, its destination concurrency by default and when configured, its settings overrides, that Mailpit takes precedence, and that a disabled relay changes nothing. For the backup, it checks that borgmatic dumps the database with --single-transaction: mysqldump's default --lock-tables would block the site's writes for the whole dump, once per repository. For DRUPAL_URI, it checks the URL of a project domain over https, with a port, and with a publicdomain. The Service domain regression job runs these checks, Drupal/DrupalPractice coding standards, and PHPStan (using phpstan.neon) in develop and feature/* branch pipelines. Its lint tools are installed separately so they do not alter the plugin's dependencies. The tool installation sets COMPOSER_BIN_DIR explicitly to .qa/vendor/bin: shared Composer artifacts export a different bin directory, which must not redirect these isolated tools into vendor/bin.

The shared validate stage runs in branch pipelines for develop and feature/*. Merge requests get no pipeline of their own, so a merge request reflects the pipeline of its source branch. Use a feature/<issue>-<description> branch and require both its full validate stage and Service domain regression job before merging; branches outside feature/* run neither check.

Release flow

Feature and fix merge requests target develop. The shared CI configuration runs Publish Release on develop unless SKIP_PUBLISH_RELEASE=1; that job clones develop and invokes the shared merge command for the release merge. The resulting Merging develop into main merge request is separate from the feature/fix MR.

The main pipeline's Tag Release job recognizes a commit beginning Merge branch 'develop' into 'main' (also release into main, or a commit containing [tag release]). It runs gen-semver and creates the generated tag on main. [MAJOR_VERSION], [MINOR_VERSION], [PATCH_VERSION], and [REVISION_VERSION] select an explicit increment; skip-tag suppresses tagging. The tag pipeline's Build Package Tag job publishes the tag to GitLab's Composer registry. Do not merge the fix or the release MR, or trigger tagging, until the change has been reviewed.

After a reviewed release, rebuild the production Compose file and deploy it to restore the public Invoice Ninja route. Production jobs install the newest release; pipeline builds follow each project's lock file. Reverting the change would restore the private production route and break the public Invoice Ninja URL when the private domain is set.