Docker - Making Application Deployment Easy

It has been a busy few months for me. Not only has it been the christmas holidays but I have also spent time playing with and implementing some exciting new technology for our company.

One of the main tools I have been looking at is Docker which is a fantastic tool that enables you to create a simple Dockerfile inside your project with a list of server installation commands. This then automagically creates a 'container' running on your machine that runs a server in a virtual space.

Before Docker we were using the well known MAC OSX tool MAMP on our machine to essentially host a local server environment which has served us well over the last few years. 

How we used to deploy our applications

  • Start up the MAMP service on our machines
  • Create our application
  • Run our build processes
  • Check our code into the master branch
  • Tag a release
  • Push the application code to our server instance
  • Check that the code works! This could throw up certain issues with PHP version or imagemagick not being on the machine etc...

The biggest problem with this is having to essentially check that the Linux server we are deploying on has the required modules or environment that can run the application. For example, when building a Laravel project on our local machines we found that it already has all the server requirements using the prebuilt PHP version that runs on MAMP but once we push our code to the server we than find that it is running an older version of PHP and has no mcrypt library. Grrr. Pain and suffering ensues...! Docker with Amazon Web Service changes all this.

The main features are:

  • It allows you to essentially tailor your own packages and operating system
  • It allows you to setup environment variables that relate only to the server instance you are running. This means that you can create local, staging and production server instance easily.
  • The Dockerfile can be checked into our GIT repositories which means that each member of the development team can essentially run the same server environment via the container. Any change to the environment can then be amended inside the Dockerfile and then run by the developer to bring their project in line with the other developers in the team.
  • It allows you to create and manage server images e.g. a server running a fully managed mysql server. You can download these images directly from the Docker Hub to get going quickly!
  • A Docker container can be started up in minutes.
  • You can run npm services such as Gulp when a deployment is made.
  • It has seamless integration with Amazon Web Services via the Elastic Beanstalk service.
  • It is cleaner as you are only running the software packages you need in order to run your applications.
  • Can be run alongside Vagrant. We use the popular VM machine VirtualBox which we have used on some of our Laravel projects.

When first looking at Docker I followed the tutorial on their site which is extremely easy to get to grips with. There are a few server commands so a working knowledge of Linux is needed but ultimately server containers can be directly managed through their GUI called Kitematic. This helps you to manage the port numbers, environment variables, ssh access to your containers etc. 

So why is Docker so popular? Well containers are in fact old technology dating back to 2000 of which Google offered a similar technology but the difference is that Docker runs an LXC container. This makes it extremely portable, fast and is ideal for cloud based deployment.

Our deployment process now looks like this

  • Bring down a docker image running the PHP version we need.
  • Make any necessary amends to our Dockerfile such as required libraries.
  • Run the container on our local machines.
  • Create our application and follow our normal GIT practices.
  • Initialise an Elastic Beanstalk server uploading our Docker based server with our code contained.
  • Have a cup of tea!

As you can see, this is so much easier as it allows us to work knowing that our servers will be running the packages and OS that we need whilst also allowing us to easily and collaboratively on our applications without worrying about the the deployment process.

If you have not done already I would certainly recommend you start looking at container based deployment. It makes things super easy 

Let me know if you have used Docker and how you have found it in the comments below!