Skip to main content

Setting up a drupal development env using docker image on mac os.

I have been trying to try various ways in which i can make building and destroying development environments quickly and also make them as close to production as possible, i have tried using vagrant before till i was bitten by the docker bug.

There is an official docker image for drupal 8 and drupal 8 on the docker hub, i have tried using them before it wasn't a great wow moment to be honest.

Creating a drupal image using official drupal docker image form docker hub.

The docker image did not have drush or drupal console so it was a bit disappointing. I searched and came across https://hub.docker.com/r/iiiepe/nginx-drupal/ The guys have done a lot of work in using docker in their deployment workflow, so i wanted to give this a try.

I could have used docker hub to pull the iiiepe image, but i wanted to see what is inside and if i need to make changes i could.

I first created a folder in my docker subfolder, I normally keep docker images and my projects separate. I checked out the git repo https://github.com/iiiepe/docker-nginx-drupal

Obviously you need to have docker installed and configured properly, you can find a lot of tutorials for this on the internet, but basically you need to start your default docker machine i.e.

docker-machine start default

then, set the env like so

docker-machine env default

and type the command with eval() in the output of docker-machine env default command.

Now i am ready to create the docker images as below:

I went to the folder which has the dockerfile, then gave the following command

docker build -t drupalprogrammer/nginx-drupal .

This will pull appropriate images and begin to build images, in a few mins this will be all done and you can check the images by giving the docker images command


We will also need a mysql image for our drupal container to work with, we could have gone for the official mysql image however it doesnt work very well with os x because we want to keep the data outside the container and there is some work required to create scripts to allow this to happen.

There is instructions on the official mysql images page i.e. https://hub.docker.com/_/mysql/ i tried to use the instructions to load the data outside but could not get it to work. Luckily little googling led me to another image we can use.

run the following command:

docker run --name mysql-data -v /Users/nidash/data:/var/lib/mysql -p 3306:3306 -d dgraziotin/mysql

This will pull dgraziotin/mysql image and expose the 3306 port to use.

Now give the following command docker ps this shows the some-mysql container working, great job. 

The first time you create the container this will also create an additional user called admin with a random generated password, to find the password you need to look at the docker logs like so.

docker logs mysql-data

So this shows the password like below:

You can now connect to this MySQL Server using: mysql -uadmin -p47nnf4FweaKu -h -P Please remember to change the above password as soon as possible! MySQL user 'root' has no password but only allows local connections

Using a mysql client connect to the mysql server and change your password eg.

SET PASSWORD FOR 'admin'@'%' = PASSWORD('password');
Now we need to the drupal container to be up as well, so here is the command to use.

docker run -d -p 8000:80 -v /Users/nidash/work/drupal7/:/var/www -v /Users/nidash/work/drupal7/sites/all/default/files:/var/www/sites/default/files  drupalprogrammer/nginx-drupal

We need to map 2 volumes, /Users/nidash/work/drupal7 or where the codebase is to /var/www and because drupal is drupal and has files inside the code base, we need to map and mount this separately hence the other -v.

Complete the installation and that is it. Ensure the database host name is set as the IP the docker-machine env default command reports.



Comments

Popular posts from this blog

Create a drupal development environment using docker.

Currently at work i am using docker to streamline and speedup of development and deployment to testing and production, I am using symfony currently and our app is dockerised, i wanted to do the same for drupal based apps.

I searched for a official drupal docker repo and i did find this. https://www.drupal.org/node/2538074

Unfortunately there was very terse explanation but pretty much worked, i found a few hiccups along the way so wanted to share what i did.

Pre-requisite:
Install docker for your environment. Lots of details are available at https://docs.docker.com/ explaing docker and installing docker for your environment.

The docker repo holds the drupal container at https://hub.docker.com/_/drupal/, following the instructions this is how to create the drupal container:

In order to use my code base we need to mount the volume with the -v directive as below, we do this in one command:

docker run -v /$HOME/work/drupal8:/var/www/html -p 8080:80 --name mydrupal -d drupal

this will create…

Use feeds module to import XML data in Drupal 7

Recently i had to setup a xml import process to import data from an external supplier on a regular basis, the filename and format was not changing and i could choose where to store the file. Following is how i set it up.

First we need to download the following modules

feeds
feeds admin ui
feeds_xpathparser
ctools
job_scheduler

enable the above modules.

We will need a sample XML so this will be the one we will use for this demonstration:

<?xml version="1.0" encoding="utf-8" ?>
<!-- Sample for demonstration of processing XML feeds with feeds module -->
<Orders>
<Order>
<CustomerID>10</CustomerID>
<Order_Number>1</Order_Number>
<Order_Total>100</Order_Total>
<Currency>£</Currency>
</Order>
<Order>
<CustomerID>11</CustomerID>
<Order_Number>2</Order_Number>
<Order_Total>40</Order_Total>
<Currency>$</Currency>
</Order>
</Orders>


How do you expose your legacy database tables to views in drupal 6 Part 1

This is a 2 part post, that shows how I exposed a legacy table to views in drupal and used the incredible power of views to create many combinations static and conditional views. This was very helpful for my client.

I had a requirement that warranted exposing existing database table to views, so that views can contain data from this table.  To enable this to happen, the following steps need to be taken.
In a custom module you need to first define the views_api hook as following:
function candidate_views_api(){ $view = array(); $view = array('api' => 2, 'path' => drupal_get_path('module','candidate'). '/views'); return$view; }
candidate module was a custom module which I already had, so it made sense to add this hook here. 
The important bit here is telling the drupal sub-system where the views file will reside. 
Then create a file with your <modulename>.views.inc in my case it was candidate.views.inc, this file should have two hooks, one …