Setting Up Drupal with Docker Compose


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'

    image: mariadb:latest
      MYSQL_DATABASE: drupal
      - drupal_mariadb_data:/var/lib/mysql
    container_name: drupaldb
    restart: always

    image: drupal:latest
      - "80:80"
      DRUPAL_DB_USER: root
      DRUPAL_DB_PASSWORD: drupal
      - drupal_data:/var/www/html
    container_name: drupal
      - drupaldb
    restart: always


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

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!

You may also like...