DEV Community

Cover image for How to Docker? - The strategic value
Stefan Fiedler
Stefan Fiedler

Posted on

How to Docker? - The strategic value

Chances are you already know what Docker is, maybe you have already worked with it for a while or you just got started. Either way, you probably wouldn't want to go back. So for someone who might have missed out on the action, why is it that everyone keeps talking about Docker? Why should you switch and what strategic value will you gain?

This short introduction to virtualisation and containerisation is supposed to help you understand, how Docker can save you time, money and headaches. To understand why Docker is helpful in the first place, let's look at some of the most common issues when developing any kind of application, site or service.

But it works on my machine!

Imagine the following scenario: You are supposed to support your coworkers during the development of an existing application. The first thing you do is check out the git repository to pull the most recent source code onto your local machine. Next, you install the application dependencies, in this example, we are using composer and the node package manager.

So you might try to install the composer dependencies, but wait, what's that?

1- dealerdirect/phpcodesniffer-composer-installer v0.5.0 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
Enter fullscreen mode Exit fullscreen mode

Looks like you have a different composer version installed on your machine which is not compatible with the project. So you have to downgrade your composer installation to version 1.

Next, you install the frontend dependencies using the node package manager, is that another error?

1npm WARN notsup Unsupported engine for semver@7.3.2: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"6.14.4"}) 2npm WARN notsup Not compatible with your version of node/npm: semver@7.3.2
Enter fullscreen mode Exit fullscreen mode

Unsupported node version? This time we need to upgrade our locally installed version. But will this maybe break another project you have been working on? Do you have to down- and upgrade your tools every time you switch projects?

Local development and required services

Finally, after hours of figuring out the appropriate versions of all the required tools you almost have the application up and running. All you're missing is a database to store the app's data, an SMTP server to send emails and a Redis instance to cache pages.

You can imagine how all these services are again dependent on a specific version. Installing everything is going to take hours and even then you might run into more issues. Maybe you forgot to install a PHP extension and suddenly you have even more issues than when you started.

Wouldn't it be nice if we could somehow avoid facing these challenges?

Docker to the rescue!

This is where we meet Docker, an open platform for developing, shipping, and running applications.

The basic idea is to separate the application environment from your local machine. This environment should be the exact same for everyone working on the project, it should contain all required tools and services and it should be easily expendable/scaleable. Such an environment is called a container and the following summary from the official Docker website explains the main goal:

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.

Source: What is a container? Official Docker explanation

Isn't this just a virtual machine?

Chances are, you have worked or at least heard of a virtual machine. It is basically a separate operating system running on top of your main operating system. Docker follows a similar route but avoids one main constraint - size. A normal VM-image (containing the whole operating system) is much larger in size than a Docker image. This can be accomplished by Docker utilising the main OS's kernel.

Integrations and the Docker-Hub

There are already plenty of integrations for docker. An example would be hosting providers, supporting or offering Docker image-based solutions. This also nicely integrates into existing continuous delivery and deployment pipelines.

We can't talk about Docker and not mention the Docker-Hub - a service build for finding and sharing images. You can find official vendor images for all kinds of use cases. Images range from simple web servers, database applications and even whole operating systems.

See for yourself by visiting the hub.

Docker - not if, but when?

Making the switch to Docker should not be a question of yes or no, but rather of when!

The long- and short term benefits are endless, here are our top three:

  1. Speed: Developers are enabled to rapidly set up new or existing projects within minutes and share that same development environment with all team members.

  2. Reusability: The same Docker image can then be used to speed up the deployment and save you the extra setup and maintenance of a traditional server.

  3. Testability: Future updates can be tested and reviewed before being deployed to the production environment, decreasing the risk of running into issues post-deployment.

This article will be part of a series about Docker best practices at Taikonauten. Stay tuned and we're happy about feedback and questions you want to know more about.

Top comments (0)