drupal|March 03, 2018|2 min read

How to use Docker for Drupal 7 Dev envirnoment

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.

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 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…

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…

Latest Posts

Software Security in the AI Era: How to Write Secure Code When AI Writes Code Too

Software Security in the AI Era: How to Write Secure Code When AI Writes Code Too

In 2025, 72% of professional developers used AI-assisted coding tools daily. By…

SQL Injection: The Complete Guide to Understanding, Preventing, and Detecting SQLi Attacks

SQL Injection: The Complete Guide to Understanding, Preventing, and Detecting SQLi Attacks

SQL injection has been on the OWASP Top 10 since the list was created in 200…

Building a Vulnerability Detection System That Developers Actually Use

Building a Vulnerability Detection System That Developers Actually Use

Here’s a stat that should concern every security team: 73% of developers say…

How to Be a Full-Time Freelancer: Resources, Finding Clients, and Building a Sustainable Business

How to Be a Full-Time Freelancer: Resources, Finding Clients, and Building a Sustainable Business

Making the leap from full-time employment to freelancing is one of the most…

Deep Dive on Elasticsearch: A System Design Interview Perspective

Deep Dive on Elasticsearch: A System Design Interview Perspective

“If you’re searching, filtering, or aggregating over large volumes of semi…

Deep Dive on Apache Kafka: A System Design Interview Perspective

Deep Dive on Apache Kafka: A System Design Interview Perspective

“Kafka is not a message queue. It’s a distributed commit log that happens to be…