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

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Most developers use Claude Code like a search engine — ask a question, get an…

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Every office lobby has the same problem: a visitor walks in, nobody’s at the…

Server Security Best Practices — Complete Hardening Guide for Production Systems

Server Security Best Practices — Complete Hardening Guide for Production Systems

Every breach post-mortem tells the same story: an unpatched service, a…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF have been in the OWASP Top 10 for over a decade. They’re among the…

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

The OWASP Top 10 is the industry standard for web application security risks. If…