drupal2 Min Read

How to use Docker for Drupal 7 Dev envirnoment

Gorav Singal

March 03, 2018

TL;DR

Use Docker with official Drupal 7 and MariaDB images to quickly spin up a local dev environment from your production backup.

How to use Docker for Drupal 7 Dev envirnoment

I have been using drupal 7 from a long time, and setting up a dev environment always felt bit tricky. Thanks to docker, life becomes easier now.

In this post, I will show how I setup my drupal 7 environment from my production environment. And, do any development work.

Pre-requisites

I have taken backup from my website running in production. To be precise, I have taken backup of "sites" folder of drupal installation which has all the static files, and theming, modules.

And, I have taken backup from mariadb running. I will use this backup in next steps.

Docker part

I have prepared a docker-compose.yml file. It has all the dependencies I require:
  • Drupal 7 Official Image
  • Mysql/MariaDB Official Image
  • Phpmyadmin official image

Drupal 7 Image

I have passed my"sites" folder locally backed up from production website. In the docker-compose.ymlfile, Replace:LOCAL_SITES_FOLDER with actual local path.

Mysql/MariaDB Image

Prepare a local path where you want to save yourdatabase changes. Otherwise, when the stack goes down with docker-compose, all the changes will be lost. For this, in docker-compose.yml file, ReplaceLOCAL_MYSQL_FOLDER with actual folder path.

Also, you can set a custom password for your database as well. ReplaceMY_MYSQL_PASSWORD with the desired password.

Till now, I have not imported database yet.

Run the Docker stack

Start things up by running: ``` docker-compose up -d ```

It should start three container. You can see these three by running docker ps command.

Import Mysql/MariaDB database

These steps you have to do first time only.

Now, open localhost:8084, where we have configured phpmyadmin to open up.

  • Put username as root, and put the password you gave.
  • Create a database, give a name.
  • Click on Import. Browse the backup file you have when you took your backup.
  • That's it.

Check Drupal website

Open: localhost:8086

Cross Check all the steps

All of the above steps needs to be done only once. Every time, you want to start your stack, you need to run following command:

docker-compose up -d

And, to stop stack:

docker-compose down

Note, by stopping stack. All of your drupal file changes, database changes, theming changes will remain. Since, we have passed the local disk paths.

Everytime, you start the stack, you will get all the changes from last time.

Enjoy.

Share

Related Posts

Drupal: How to block a user by email programatically

Drupal: How to block a user by email programatically

Many times, while administering your drupal website, you must have encountered…

Drupal Helpful codes for database queries

Drupal Helpful codes for database queries

Being a drupal user from last around 5 years, I used to know small codes for…

Drupal 8: How to Export and Import View

Drupal 8: How to Export and Import View

You have created some views, and want to port it to your production environment…

Drupal Code: Fetch Link, Title, Category names, tag names from every article

Drupal Code: Fetch Link, Title, Category names, tag names from every article

See the code below: The output will be 4 columns separated by comma. You can…

Drupal 7: How to save a node programmatically and add an image field from a public URL

Drupal 7: How to save a node programmatically and add an image field from a public URL

Note: I have public URLs of these images, which I want to save. return…

Drupal 7: How to implement cron tasks (hook_cron and hook_cron_queue_info) that takes much time

Drupal 7: How to implement cron tasks (hook_cron and hook_cron_queue_info) that takes much time

hook_cron() suggests to put tasks that executes in shorter time or non-resource…

Latest Posts

AI Video Generation in 2025 — Models, Costs, and How to Build a Cost-Effective Pipeline

AI Video Generation in 2025 — Models, Costs, and How to Build a Cost-Effective Pipeline

AI video generation went from “cool demo” to “usable in production” in 2024-202…

AI Models in 2025 — Cost, Capabilities, and Which One to Use

AI Models in 2025 — Cost, Capabilities, and Which One to Use

Choosing the right AI model is one of the most impactful decisions you’ll make…

AI Image Generation in 2025 — Models, Costs, and How to Optimize Spend

AI Image Generation in 2025 — Models, Costs, and How to Optimize Spend

Generating one image with AI costs between $0.002 and $0.12. That might sound…

AI Coding Assistants in 2025 — Every Tool Compared, and Which One to Actually Use

AI Coding Assistants in 2025 — Every Tool Compared, and Which One to Actually Use

Two years ago, AI coding meant one thing: GitHub Copilot autocompleting your…

AI Agents Demystified — It's Just Automation With a Better Brain

AI Agents Demystified — It's Just Automation With a Better Brain

Let’s cut through the noise. If you read Twitter or LinkedIn, you’d think “AI…

Supply Chain Security — Protecting Your Software Pipeline

Supply Chain Security — Protecting Your Software Pipeline

In 2024, a single malicious contributor nearly compromised every Linux system on…