How to use Docker for Drupal 7 Dev envirnoment

March 03, 2018

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.


Similar Posts

Latest Posts