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

Explore useful Automation Techniques with Powershell on Windows

Explore useful Automation Techniques with Powershell on Windows

Introduction We will list few interesting automation techniques with powershell…

How to install Perl from Command Line for Automation on Windows and Dockerfile

How to install Perl from Command Line for Automation on Windows and Dockerfile

Introduction Often in automation, we need to install stuff from command line…

How to install Mongo DB Driver for Php 7.x

How to install Mongo DB Driver for Php 7.x

The simplest way to install driver for php is using pecl. When I tried to run…

Dockerfile for building Python 3.9.2 and Openssl for FIPS

Dockerfile for building Python 3.9.2 and Openssl for FIPS

Introduction In previous posts, we saw how to build FIPS enabled Openssl, and…

A Practical Guide on how to work with Git log command and history

A Practical Guide on how to work with Git log command and history

Introduction In this post, we will see ways to look at git history logs. For…

Python 3 - Magical Methods and Tricks with extremely useful methods

Python 3 - Magical Methods and Tricks with extremely useful methods

This post will show some really awesome tricks in python. Get the power of a…

Latest Posts

System Design Patterns for Managing Long-Running Tasks

System Design Patterns for Managing Long-Running Tasks

Introduction Some operations simply can’t finish in the time a user is willing…

System Design Patterns for Real-Time Updates at High Traffic

System Design Patterns for Real-Time Updates at High Traffic

The previous articles in this series covered scaling reads and scaling writes…

System Design Patterns for Handling Large Blobs

System Design Patterns for Handling Large Blobs

Introduction Every non-trivial application eventually needs to handle large…

Explaining SAGA Patterns with Examples

Explaining SAGA Patterns with Examples

In a monolith, placing an order is a single database transaction — deduct…

System Design Patterns for Scaling Writes

System Design Patterns for Scaling Writes

In the companion article on scaling reads, we covered caching, replicas, and…

Serverless vs Containers — The Decision I Keep Revisiting

Serverless vs Containers — The Decision I Keep Revisiting

Every time I start a new service, I have the same argument with myself. Lambda…