Setting Up Drupal with Docker Compose
Introduction:
Drupal is a popular content management system that allows you to create and manage websites with ease. By using Docker, we can quickly set up Drupal along with its MariaDB database, making the deployment process straightforward and portable. In this guide, we’ll show you how to run Drupal and MariaDB containers with Docker Compose.
Step 1: Install Docker and Docker Compose
Before proceeding, ensure you have Docker and Docker Compose installed on your system. If not, follow the official Docker installation instructions for your operating system.
Step 2: Create a Docker Compose File
Create a new directory for your Drupal project and navigate into it:
mkdir drupal_project
cd drupal_project
Inside the drupal_project
directory, create a docker-compose.yml
file using a text editor of your choice (e.g., nano
, vi
, or vim
), and add the following content:
version: '3'
services:
drupaldb:
image: mariadb:latest
environment:
MYSQL_ROOT_PASSWORD: drupal
MYSQL_DATABASE: drupal
volumes:
- drupal_mariadb_data:/var/lib/mysql
container_name: drupaldb
restart: always
drupal:
image: drupal:latest
ports:
- "80:80"
environment:
DRUPAL_DB_USER: root
DRUPAL_DB_PASSWORD: drupal
volumes:
- drupal_data:/var/www/html
container_name: drupal
depends_on:
- drupaldb
restart: always
volumes:
drupal_mariadb_data:
drupal_data:
Save the file and exit the editor.
Step 3: Start the Containers
To create and start the Drupal and MariaDB containers, run the following command inside the drupal_project
directory:
docker-compose up -d
Docker Compose will pull the required images (if not already available locally) and start the containers in the background.
Step 4: Access Drupal
Once the containers are running, you can access your Drupal site by opening a web browser and navigating to http://localhost
. The Drupal installation wizard will guide you through the setup process.
Step 5: Cleanup
If you want to stop and remove the containers and volumes created by Docker Compose, use the following command:
docker-compose down
Conclusion:
Congratulations! You’ve successfully set up Drupal with Docker Compose, providing a scalable and easily manageable environment for your website. Docker Compose simplifies the process of managing multi-container applications, making it ideal for running Drupal alongside its MariaDB database. Now you can focus on building your Drupal website without worrying about the complexities of server setup.
Happy Drupal development!