Docker: Virtualize Your Development Environment Right

DevOpsPUBLISHED ON July 27, 2020 | MODIFIED ON December 4, 2020

— How to reduce deployment time and cost?
— How to cut the time needed to set up a new Java project?
— How to simplify your development environment?

The answer that comes to mind first is virtualization. Let’s see what K&C’s DevOps consulting team has to say:

Why Pure Virtualization is Not an Option for You

In its essence, virtualization allows running of a few operational systems on a single machine, which turned out to be really helpful for testing purposes. But high processor loading, excessive usage of RAM and HD space, and the impossibility of reuse in case of unique configurations makes development processes too slow. Thus, virtualization doesn’t fit for software engineers and stakeholders wanting to deploy their app quickly.

In 2010 HashiCorp introduced Vagrant. As a command line utility for virtualization software, it allows running of commands like [create virtual machine] and 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
— have 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

And no wonder that not only K&C but leading software companies like Google and Facebook eventually turned to using Docker for their development matters as well.

Related Service

There no posts to show.