Introduction
Drupal is a free, open-source tool for building and managing websites and web applications. It is used as a back-end framework of all Web sites worldwide, There are multiple database types supported by this image, most easily used via Docker networks, in the default configuration.
Drupal needs software like Linux, Apache, MySQL, and PHP to work. Setting up Drupal manually can be slow and tricky. With Docker, you can automate the setup and make sure it works the same everywhere.
Why use Docker for Drupal?
Docker has become the go to tool for CMS projects like Drupal because it provides.
- Consistency: Same environment across all machines.
- Isolation: Each project runs in its own container, avoiding dependency conflicts.
- Scalability: Easily add services like Redis, Varnish, and Elastic Search.
- Faster onboarding: Developers can start immediately without complex setups.
- Reliable deployments: works seamlessly with CI/CD pipelines.
For Drupal, this means:
- No more “works on my machine” problems.
- Stable PHP, Apache/Nginx, and MySQL versions.
- Better team collaboration.
Prerequisites
Before you start, make sure you have: Docker Desktop install (Windows / macOS / Linux)
Docker Compose
Basic command-line knowledge
At least 4GB RAM (recommended)
- Quick setup: Set up Drupal CMS with minimal commands.
- Portability: Move projects between different environments easily.
- Isolation: Each project runs in its own container without any conflicts.
- Service integration: Quickly link to MySQL, Redis, or Elasticsearch containers.
- Efficiency: Developers don’t need to manually replicate complex configurations.
For additional insights into improving your Drupal performance, you can simply check out optimizing Drupal performance: Tips to develop a faster website.
Step 1: Create project directory
mkdir drupal-docker && cd drupal-docker
Step 2: Create docker-compose.yml
version: '3'
services:
Drupal:
image: drupal:11-apache
ports:
- "8080:80"
volumes:
- ./web:/var/www/html
depends_on:
- db
db:
image: mysql:5.7
environment:
MYSQL_DATABASE: Drupal
MYSQL_USER: Drupal
MYSQL_PASSWORD: Drupal
MYSQL_ROOT_PASSWORD: root
volumes:
- db_data:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
ports:
- "8081:80"
environment:
PMA_HOST: db
PMA_PORT: 3306
redis:
Image: redis:alpine
restart: always
ports:
- "6379:6379"
volumes:
db_data:
Step 3: First run
Docker compose up -d
Copy Drupal files from the container to host:
docker cp $(docker ps -qf "name=drupal"):/var/www/html ./web
Step 4: Fix file permissions (Linux)
sudo chown -R www-data:www-data ./web
sudo chmod -R 775 ./web
# Important files
sudo chmod 664 ./web/sites/default/settings.php
sudo chmod 664 ./web/sites/default/services.yml
# For production
sudo chmod 444 ./web/sites/default/settings.php
sudo chmod 444 ./web/sites/default/services.yml
Step 5: Create .env file
# Apache
APACHE_RUN_USER=www-data
APACHE_RUN_GROUP=www-data
# Drupal
APP_ENV=Dev
APP_HASH_SALT=drupal_hash_salt
# MySQL
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=Drupal
MYSQL_USER=Drupal
MYSQL_PASSWORD=Drupal
MYSQL_PORT=3306
# Redis
REDIS_HOST=redis
REDIS_PORT=6379
# PhpMyAdmin
PMA_HOST=db
PMA_PORT=3306
Step 6: Useful Docker commands
# Start environment
Docker composes up -d
# Stop containers
Docker compose stop
# Stop & remove containers
Docker composes down
# Stop & remove + volumes
Docker compose down -v
# Rebuild clean
Docker compose build --no-cache
# List running containers
docker ps
# Access Drupal shell
docker compose exec Drupal /bin/bash
# Check PHP version
docker compose exec Drupal php -v
# Drush status
docker compose exec Drupal drush status
Step 7: Access services
- Drupal → http://localhost:8080
- PhpMyAdmin → http://localhost:8081
Database connection in Drupal installer
Use these values during installation:
- Host: db
- Database: Drupal
- User: Drupal
- Password: Drupal
For advanced Drupal integrations, you might also explore headless Drupal solutions: flexible, scalable & API integration.
Common issues or fixes
File permissions → Ensure /sites/default/files is writable.
Port conflicts → Change 8080 if already in use.
DB errors → Double-check host database and credentials.
Performance on Windows/macOS → Use Docker volumes carefully, as file sync is slower.
How Docker boosts workflow
- Faster onboarding: Docker Compose up and you’re ready.
- Parallel projects: Run multiple Drupal versions side by side.
- CI/CD friendly: Easy integration with pipelines.
- Debugging: Restart/replace containers without breaking.
Conclusion
Docker Drupal is one of the smart way to modernize your development workflow. It save setup time, ensures consistency across environments, and makes scaling easier.
Whether you’re a solo developer or part of a large team, this base setup provides a strong foundation for running Drupal projects in containers.
If you want to setup and focus on optimization, don’t miss our blog on optimizing Drupal performance: Tips to develop a faster website.