Thursday, 17 August 2017

How to find differences between two docker images or containers.

Docker comes with a handy command called docker diff which allows you to find differences between the image and the container.

So if we make changes inside the container then we can find the difference from the image this is based on using the docker diff command.

But sometimes we might have to find differences between two running containers, in order to do this i found this helpful.

We can use the docker export command to export the filesystem of the container into a tarball and use our normal diff tools to compare.

This is how i did this:

Assume the image we are comparing is in our own docker registry and I would first create a container with the two images and then give the command

docker export dev025-instance -o dev05.tar


docker export dev026-instance -o dev06.tar

untar the files in separate folders and use an ide like PHPStorm to compare side by side.

For mac users there is a brew available to tap ( using

brew tap moul/moul

and then

brew install docker-diff

This does speed things up and you do not need to create containers etc, because docker-diff does that for you implicitly. However i felt it was easier with docker export commands due to large number of changes i was dealing with.

Docker diff works both with custom as well as official docker repos.

Monday, 7 March 2016

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

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

Tuesday, 1 March 2016

Creating a drupal 8 container from scratch.

I tried the official drupal container according to

Was'nt happy with the result  so i thought build one from scratch.

What i want my drupal container to do?

1. Use my codebase which will be outside the container
2. Able to install drupal - correct file system permissions.
3. Clean urls should work
4. Drush & drupal console installed
5. Xdebug installed
6. Xhprof or any other profiler installed (optional)

Anything else?

Tuesday, 23 February 2016

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.

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.

Install docker for your environment. Lots of details are available at explaing docker and installing docker for your environment.

The docker repo holds the drupal container at, 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 a drupal container using drupal code in your home folder, this brought up a new site however soon i had a problem where

Because i was using my local folders mapped to /var/www/html i need to ensure the sites/default/files are writable, normally you should be careful what permissions you should set, more information is on drupal site. for now 777 will do, so i did a chmod 777 $HOME/work/drupal8/sites/default and also created a settings.php as instructed. Also chmod 777 $HOME/work/drupal8/sites/default/files.

Now comes the database part, at this point i created another container with mysql, fortunately a official mysql repo is also available on

docker run --name mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -p 3307:3306 -d mysql:5.7

giving the command above download the mysql 5.7 image, set the root password, expose the mysql port in the container externally, now our drupal app can use this container. normally you would store the data outside the mysql container, the repo page of mysql on the docker hub discusses that, for demonstration purpose it is just fine to have out data inside.

i also connected to this database container using sequelPro and created a new database to use and named it drupal8, then continued with the installation.

Unfortunately then drupal died, with the following error:

I can again gave permissions, but ended again with another permission issue. Thank God i am using i dropped the drupal container and decided to mount modules and themes folder seperately, and use drupal core inside the container.

So first i drop the container as below:

docker rm -f mydrupal

so my modified docker run now becomes:

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

Notice the use of -v to use external folders for modules & themes otherwise use the drupal codebase inside the drupal container.

now reinstalling again. I had to drop the database and recreate a blank database and finish the install.

Somethings to remember, us the docker machine IP address, which you get by running docker-machine env default, use this IP address in the database config as well as the browser to look at your new drupal site!

All Done!