Using Docker to virtualize your development environment – the right way

The need for virtualisation, how Docker solved the resources problem and an introductory explanation of how the DevOps tool works

DevOpsUPDATED ON June 4, 2021

Docker virtualisation for DevOps testing

In this instalment of our DevOps consulting series, we look at how Docker can be used to virtualise a development environment leading to a simplification that delivers:

  • Cost efficiencies
  • Less time needed to set up a new Java project
  • Reduced deployment time

K&C - Creating Beautiful Technology Solutions For 20+ Years . Can We Be Your Competitive Edge?

Drop us a line to discuss your needs or next project

Why Pure Virtualization is Not an Option for You

In its essence, virtualization allows the running of multiple operating systems on a single machine. That is hugely helpful for testing but leads to high processor loads, excessive usage of RAM and HD space, and means unique configurations cannot be replicated and re-used. All of which slows down the development processes.

As a result, virtualization often wasn’t a viable option when speedy app deployment was a strategic requirement.

That started to change when HashiCorp introduced Vagrant in 2010. As a command-line utility for virtualization software, it allows the running of commands like [create virtual machine] and the generation of complicated configurations. As a result, you can type a single [vagrant up] line in your terminal when you want to, say, run your project with PHP isolated in Ubuntu.

Vagrant made virtualization tasks much simpler for developers, but the approach itself remained too resource-intensive, so in 2013 Solomon Hyckes introduced Docker.

How Docker Changed The Way Hardware Is Virtualized

Docker is an open-source platform that was created for rapid deployment and allows:

— setting up the same environment anywhere you need
— release of the application code in less time
— performing quality assurance more quickly

This becomes possible thanks to Docker’s container virtualization platform with processes and utilities managing RAM, HDD, CPU, etc. No matter what app you want to run inside Docker — a NodeJS web app, a Selenium server, a Java application or a Python script — each application will run in isolation inside its Docker container.

And you can create as many containers on a single machine as you need!

Under The Hood: How Docker Works

In Docker, three main components do all the magic:

Linux Containers, a technology of virtualization that allows running several isolated OS instances on one host
Cgroups, a Linux kernel feature that limits, accounts for, and isolates the resource usage (CPU, memory, disk I/O, network, etc.) of a collection of processes
Linux Namespaces (lightweight process virtualization feature), used to organize isolated places called Docker containers

Containers are similar to directories having everything applications may require to work. Each container is created from an image, a read-only template usually stored in a Docker registry (either private or public).

Dockerfile creating an image with Ruby, Sass, and Gulp installed and then launching a container on top of it:

FROM node:6.1-onbuild

# Install gem sass for grunt-contrib-sass
RUN apt-get update -qq && apt-get install -y build-essential
RUN apt-get install -y ruby
RUN gem install sass

RUN npm install -g bower gulp

RUN bower install --config.interactive=false --allow-root

ENV NODE_ENV development

# Port 3000 for server
# Port 35729 for livereload
EXPOSE 3000 35729

Sounds great, but in practice, we usually need to launch a few containers at once to build a complete development or testing environment for an application. What to do then?

One Step Further: Multi-Container Apps with Compose

Docker’s Compose is a tool introduced for defining and running multi-container applications. To configure your app’s services, you must create a Compose file. Then, using a single [docker-compose up] command, you set up and start all services required for your configuration.

Example of a docker-compose.yml file:

  build: ./app/
    - "3000:3000"
    - "35729:35729"
    - ./app/config:/usr/src/app/config
    - ./app/modules:/usr/src/app/modules
    - ./app/public:/usr/src/app/public
    - ./app/.jshintrc:/usr/src/app/.jshintrc
    - ./app/.csslintrc:/usr/src/app/.csslintrc
    MOODLE_SERVICE: appname_mobile_app

  build: ./dockerfiles/moodle/
    - "8080:80"
    - db
    - ./dockerfiles/appname/

  image: centurylink/mysql
    - "3306"
    MYSQL_DATABASE: moodle
    MYSQL_USER: moodle
    MYSQL_PASSWORD: moodle
docker-compose up -d

The above-listed file will run an app that exists in 3 different docker images: app (with a nodeJS application), moodle (with PHP scripts and the Apache web server), and db (with a mySQL database).

Long Story Short, Why Use Docker?

Docker allows running any platform with its own configuration on top of your infrastructure without overloading its resources as in the case of virtual machines. It lets you put your environment and configuration into the code and deploy it.

As a result, Docker allows our developers to:

  • be as close as possible to production
  • benefit from a fast development environment available for interactive use
  • run different applications on the same host without any conflicts
  • dramatically reduce costs by running many instances on a single server
  • bring up new processes via containers within seconds

When does IT Outsourcing work?

(And when doesn’t it?)

Related Service

Angular Development and Migration Services

Read more >

QA Consulting and Software Testing

Read more >

Kubernetes Consulting, Training, Support & Management

Read more >