An introduction to Docker and using it to set up your virtualised development environment

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

DevOpsUPDATED ON May 30, 2022

John Adam K&C head of marketing


Cover image on blog on the topic of Docker and virtualising development environments

In this instalment of our DevOps consulting series, we look at how Docker can be used to virtualise a development environment. And how the simplification the containerisation tool provides 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 of the development environment is usually not an option

In its essence, virtualization makes it possible for multiple operating systems to run on a single machine. That is hugely helpful for software 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 process.

As a result, virtualization often wasn’t historically 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 as a development environment

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

  • the set up of the same virtual development environment anywhere you need
  • faster release of application code
  • faster, more efficient quality assurance

These benefits are made possible by Docker’s container virtualization platform with processes and utilities managing RAM, HDD, CPU, etc. No matter what piece of software you might want to run inside Docker — a NodeJS web app, a Selenium server, a Java application or a Python script — each microservice will run in isolation inside its Docker container.

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

When does IT Outsourcing work?

(And when doesn’t it?)

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?

Docker Compose for multi-container apps

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

Docker and Kubernetes: a match made in heaven for cloud-native applications

While Docker does have its own Docker Swarm tool that can be used to scale the orchestration of container clusters in more complex cloud-native applications, Kubernetes has become the industry standard – a fact even recognised by Docker Enterprise’s new owners Mirantis. For more information on how Docker and Kubernetes work together in a cloud-native, DevOps architecture, you can refer to our article Kubernetes vs Docker: a partnership not a competition.

Long Story Short, Why Use Docker?

Docker allows you to run 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

If you need a software development team or team augmentation with Docker and DevOps expertise for a current or upcoming project, please do get in touch! We’d be delighted to hear the details.

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