This guide uses Docker Compose to run Drupal with the official Docker image.
For Docker installation, see Docker.
Create docker-compose.yml with Drupal and a database:
cat <<'YAML' > docker-compose.yml
services:
drupal:
image: drupal:11-apache
restart: unless-stopped
depends_on:
- db
ports:
- "8080:80"
volumes:
- drupal_modules:/var/www/html/modules
- drupal_profiles:/var/www/html/profiles
- drupal_themes:/var/www/html/themes
- drupal_sites:/var/www/html/sites
- drupal_web:/var/www/html/web
db:
image: mariadb:10.11
restart: unless-stopped
environment:
MYSQL_DATABASE: drupal
MYSQL_USER: drupal
MYSQL_PASSWORD: change-me-to-secure-password
MYSQL_ROOT_PASSWORD: change-me-to-secure-root-password
volumes:
- db_data:/var/lib/mysql
volumes:
drupal_modules:
drupal_profiles:
drupal_themes:
drupal_sites:
drupal_web:
db_data:
YAML
Important: Replace passwords with strong, unique values before starting.
docker compose up -d
Open http://YOUR-SERVER:8080 and complete the Drupal setup wizard.
You’ll need to provide:
drupaldrupaldb (Docker service name)For production deployments:
latestcat <<'YAML' > docker-compose.yml
services:
drupal:
image: drupal:11-apache
restart: unless-stopped
depends_on:
- db
ports:
- "8080:80"
volumes:
- drupal_modules:/var/www/html/modules
- drupal_profiles:/var/www/html/profiles
- drupal_themes:/var/www/html/themes
- drupal_sites:/var/www/html/sites
- drupal_web:/var/www/html/web
db:
image: postgres:16
restart: unless-stopped
environment:
POSTGRES_DB: drupal
POSTGRES_USER: drupal
POSTGRES_PASSWORD: change-me-to-secure-password
volumes:
- db_data:/var/lib/postgresql/data
volumes:
drupal_modules:
drupal_profiles:
drupal_themes:
drupal_sites:
drupal_web:
db_data:
YAML
| Volume | Purpose |
|---|---|
modules |
Contributed and custom modules |
profiles |
Installation profiles |
themes |
Custom themes |
sites |
Site configuration, files, settings.php |
web |
Drupal core web root |
db_data |
Database persistence |
To connect to an existing MySQL/MariaDB server:
services:
drupal:
image: drupal:11-apache
ports:
- "8080:80"
volumes:
- drupal_sites:/var/www/html/sites
Then configure database connection during installation.
Deploying Drupal in containers for production? Our consulting covers:
Get expert help: office@linux-server-admin.com | Contact Page