Software companies constantly empower their developers to deliver new customer experiences quickly. Docker is one of the most popular tools to do so. Here’s the what, how, when and whys of Docker.
What is Docker
The Docker Platform is a set of integrated technologies and solutions for building, sharing and running container-based applications, from the developer’s desktop to the cloud. It is an open source tool designed to make it easier and faster to create, deploy and run applications, using “containers”, a virtualized environment where all code, dependencies and libraries are packaged for the code to run.
It’s not like a Virtual Machine. Containers do not need to replicate the entire operating system. Each container has its own CPU, memory and network interfaces. They do NOT depend on a specific operating system. Multiple containers can run on the same machine and share the OS kernel with other containers, each running as isolated processes in user space. Also, they take up less space than VMs (container images are typically tens of MBs in size) and can handle more applications.
How to use Docker
There are two possible options to run a container:
A. Run an existent image from Docker Hub
For example, in case we need to create a simple API, we can use a pre-existing Node image. The only thing we need to do is write:
B. Create your own Dockerfile, whit your needs
In the source project, we need to create a description file, called Dockerfile, specifying everything we need in terms of OS, environment variables and how to get our application in there. Each instruction in the Dockerfile adds a new “layer” to the image, with layers representing a portion of the images file system that either adds to or replaces the layer below it. Layers are key to Docker’s lightweight yet powerful structure. Here's a simple Dockerfile example:
Once we got the Dockerfile complete, all we need to do is build the image and then run the container:
When to use Docker
One of Docker’s benefits is that it can be used for multiple tasks such as app or web development and different IT solutions.For instance, you can host remote servers by creating a remote Docker host and connecting to it locally. Also, it’s widely used to host frontend apps, APIs and for environment building.
Why use Docker
Some of this tool’s best advantages are:
Speed upgrade: it’s easy to manage, deploy and create containers. You can easily improve your workflow.
Stability: all the libraries used will work with the same version. This means that the “environments” (dev, stage and prod) can be all the same and work the same in different computers.
Onboarding: every time you onboard a new developer in a project they need to set up a lot of things like installing SDKs, development tools, databases, add permissions and so on. With Docker you can just start working on the project with a shared image container right away.
Everyone uses it: it’s one of the most popular tools. This allows having more containers/images created that can be used as templates, trainning videos and documentation to resolve any problems you may encounter.