<center>
Why Everyone Should Know About Docker
===
<big>
**What is Docker and how does it work? This introduction walks you through the benefits of this core technology and shows you how to get started with it.**
</big>
*Written by [Angel](https://twitter.com/afreydev). Originally published 2020-09-15 on the [Monadical blog](https://monadical.com/blog.html).*
</center>
---
If you’re keeping up with the [trends in technology](https://trends.google.com/trends/explore?date=today%205-y&q=docker,%2Fg%2F11b7lxp79d), you’ll have seen a lot of articles about Docker and its increasing importance in an IT environment. There are a lot of conflicting opinions on Docker, and it doesn’t always get a good rap. Some say it’s too hard to learn, or is only really relevant to sysadmins and SREs. Others (especially people waiting for builds to complete) complain that it’s way too slow. However, fans of Docker, like me, love what it can do for scalability, homogenization, and deployment timelines.
<center>
![docker logo](https://docs.monadical.com/uploads/upload_217069157fa4ce37bab61da18501434c.png)
</center>
So what is Docker? Docker is a technology that enables you to package software so that it can be easily deployed in any environment. These packages are called containers. Docker offers a range of benefits across different roles in a development team. For example:
1. **IT support engineer:** Docker can help you to deploy applications, allowing you to take advantage of continuous integration and delivery platforms without having to compile or install dependencies directly. Docker is responsible for packaging and deploying the software so your team will have fewer problems with the building process and configuration management.
2. **Developers:** Docker can help to standardize and homogenize environments. This means that the development environment you’re working in will be very similar to the staging and production environments (you won’t be able to get away with saying “but it works on my machine!”). For developers, this is like having a sprinkle of operations added into the codebase. Because of this, ultimately, containerized applications reduce the need for support work and save you time when it comes to debugging.
3. **Software architects:** High scalability and availability are obviously requirements for a corporate platform. Docker enables your team to make better use of the available resources and allows you to grow your infrastructure in a horizontal way by distributing many containers across multiple servers. For example, if your company sells online, you’ll be able to survive rapidly scaling up and then back down again for Black Friday without any issues. Microservices architectures can also be implemented more easily when you have a container ecosystem.
## The Nitty Gritty
Docker is a technology that does something similar to virtualization (from a UX perspective). Under the hood, it actually uses the Linux kernel’s own mechanisms to divide up resources like process IDs, network sockets, and filesystem trees into separate namespaces for each container. The main difference between Docker and virtualization is the different low-level approach to application containment. With a virtual machine, an isolated pool of “virtual” computational resources are divvied out through a special kind of software called a hypervisor. (Examples of hypervisor technologies include VMWare, Xen, and VirtualBox.) By contrast, Docker uses un-virtualized resources shared with its host system, but uses cgroups and kernel namespaces to effectively present a fake “isolated” system to each application within. Practically speaking, Docker is able to more efficiently share system resources across applications and their host, because it doesn’t have the added overhead of passing all resource accesses through a hypervisor process.
<center>
![docker and virtual machines comparisson](https://docs.monadical.com/uploads/upload_0bedfaf129c78f2ea21bc3b3dea33b1b.png)
</center>
## Some foundational concepts:
**Image**: An image is a bit like a template. It has the “hard-coded” file layer of Docker. This means that it contains the file system of the operating system, the libraries you might need for your application, and, finally, the source code. (If you know a bit about object-oriented programming, an image is something like a Class definition.) To create an image, you need to write a special file called a Dockerfile. Dockerfile helps you to install and configure everything that your image needs to work.
**Container**: A container is like an instance of an image. Docker takes an image definition and runs it like any other Linux process, but the application within the container sees a completely clean view of the system, untainted by anything else running on the host. Usually an image deploys a service or an application that you can use on its own or jointly with other containers.
At a low-level, a container is something that groups a set of resources by using some Linux kernel features like namespaces and cgroups. Namespaces are a feature that help to segment different process groups from each other. They show specific resources (e.g., the hostname, the file system, the communication between processes, processes, network devices, and system users) to a set of processes (i.e., the containers). Cgroups are another Linux kernel feature used to limit and isolate computational resources (CPU, memory, disk I/O, network). There are different approaches to container technology, but Docker is the most popular.
## What do I need to know before I learn Docker?
One possible path is the one I took -- when I first started looking into Docker, I realized that if I wanted to take full advantage of it, I’d need to have a pretty good understanding of Linux. For tasks like software installation and decoupling configuration, and so you can use more advanced Docker tools like Docker-compose, I also recommend the following:
* **Learn Linux OS, preferably Ubuntu/Debian.** When you are building a new image, you'll need to know the basic commands to navigate the file system and copy or move files. Ubuntu is a good distro if you are a new Linux user because it has a graphical interface that’s super user-friendly.
* **Learn how to install OS packages by using apt or yum commands.** This is important because in order for them to work, your Docker images might need some software packages. For example, if you’re working in Django, you need to install Python into the image. For that, usually you use package managers like apt in Debian/Ubuntu distros or yum in Red Hat derived flavors.
* **Figure out how environment variables work.** Environment variables are the best way to decouple software from its [configuration](https://12factor.net/config). This is good practice if you don't want to edit a lot of config files before a deployment in production. For example, all you need to do is configure the right settings, depending on whether you are in development or production.
* **Learn some scripting programming languages like bash (or Python).** This is basically so you can do more advanced stuff inside your containers, for example, compile something or connect to other services (or containers).
* **Learn other programming languages like Java, PHP, or Python.** It's good to know a little more about the software you want to run using Docker and how it's made.
* **Learn a little about basic networking.** If you want to use Docker-compose (an advanced topic used to run multiple containers simultaneously), sometimes you'll have to set a Docker network for it. Minimally, you should know how to define the possible IPs for your containers.
<center>
![learner](https://docs.monadical.com/uploads/upload_0b3d6bfe5f0d8692876290f3a28316ba.png)
</center>
## How do I start to use Docker?
Learning Docker is a bit of an investment. If you don’t have a broad enough background, you might need to study quite a range of technologies. The payoff is worth it, though: once you’ve mastered Docker, you’ll have a better understanding of application distribution within modern architecture, and an insight into how corporate web applications are deployed.
Docker has a lot of documentation on its official website, so you can study it directly there. There are also tons of good technical blogs and courses in ed-tech on platforms like Udemy. I’ve included some of my favorite resources at the end of this post. If you want to brush up on your background info before you get started, skip to the "Resources for Docker" section using the navigation menu. If you're ready to get going right away, read on!
For some people who prefer practical hands-on learning to a theory-centric approach, it may be easier to start by learning Docker Compose before learning Docker itself. Docker Compose provides a high-level way to describe a collection of containers, the relationships between them, and the services they expose to the world. This allows you to see how Docker is used in production without needing to understand as much of the underlying theory, while still exposing you to the main concepts that you’ll need to understand container orchestration in general.
To begin with, you should install Docker following the [official documentation](
https://docs.docker.com/get-docker/).
Once you’ve installed it, you can access Docker by using the shell of your operating system.
To run your first container, you can run this command:
```docker run --name my-first-container ubuntu echo "Hello Monadical"```
You’ll see this execution:
<center>
![](https://docs.monadical.com/uploads/upload_f91e3382784a836c4e05936c259a8e37.png)
</center>
### What’s happening in the first line here?
* The command option run says to Docker that it should start a container.
* The **name** option tags the container with the “my-first-container” name.
* **Ubuntu** is the image we want to use as a base for running our container.
* Finally, **echo** is a Linux command that shows a message in the user screen. In this case “Hello Monadical”.
After that, Docker begins to download the Ubuntu image, since it’s not available on the host machine. Finally, Docker adds CPU and RAM resources to the image and executes the echo command, showing us the message “Hello Monadical”.
This is a basic example, but it shows you how to get started with this awesome technology.
After that, Docker begins to download the Ubuntu image, since it’s not available on the host machine. Finally, Docker adds CPU and RAM resources to the image and executes the **echo** command, showing us the message “Hello Monadical”.
This is a basic example, but it shows you how to get started with this awesome technology.
## What other technologies does Docker enable?
Nowadays, Docker can be considered a core technology in the corporate IT environment, since it has such a foundational role in most workflows (e.g., with development, testing and deployment). It also allows organizations to use other technologies like Swarm and Kubernetes. These technologies can be useful in orchestrating tons of services deployed through Docker and they help to maintain excellent availability. For example, they can ensure that your desired quota of containers is maintained, regardless of any server failures.
<center>
![kubernetes logo](https://docs.monadical.com/uploads/upload_deafecad512f7c7a42addbec7924a37f.png)
</center>
At Monadical, we have used Docker in many of our projects, including [oddslingers](https://oddslingers.com/), synchroplicity, [archivebox](https://archivebox.io/), and [NWB](https://www.nwb.org/). If you want any help implementing Docker in your organization, give us a call!
## Resources for Docker
* dev.to is a community of software developers that believes in networked learning. Here you’ll find articles related to Docker aimed at people with a range of different levels of knowledge:
https://dev.to/search?q=docker
* Edx is an e-learning platform that collaborates with big institutions (companies and universities) on course sharing. For Docker, there are currently some courses supported by Red Hat, the Linux foundation, and AWS:
https://www.edx.org/learn/docker
* This is a really useful article from Digital Ocean with some foundational commands for working with Docker in Ubuntu:
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04
* Udemy is another good learning platform with cheap courses. You can find a lot of content on Docker here:
https://www.udemy.com/courses/search/?q=docker
* Once you start to get more proficient with Docker, Jess Fraz has loads of great stuff over on her blog:
https://blog.jessfraz.com/
---
<center>
<img src="https://monadical.com/static/logo-black.png" style="height: 80px"/><br/>
Monadical.com | Full-Stack Consultancy
*We build software that outlasts us*
</center>
---
Recent posts:
- So you want to build a social network?
- Mastering Project Estimation
- Typescript Validators Jamboree
- Revolutionize Animation: Build a Digital Human with Large Language Models
- View more posts...
Back to top