Introduction to Containers and Docker
In this lesson, we'll discuss containers and Docker and why they are important. You'll learn how to create minimalist, standalone, statically-linked Go executables that we can easily package in lean Docker containers.
We'll cover the following
Overview
Containers have conquered the DevOps arena. Most modern large-scale systems, especially in the cloud, are deployed using containers. However, containers are very helpful for command-line programs too. The basic idea is that you can package your application with all its dependencies including the OS, in a container and then run it anywhere without worrying about the environment. For a program like multi-git we had to go through a lot of trouble to create cross-platform binaries and make it self-updateable. However, there is another way to accomplish the same end result that may be more attractive to you. Let’s get started…
Quick introduction to containers and Docker
Docker is a company that popularized containers when it introduced the Docker runtime and CLI in 2014. Since then, Docker’s core has become the open-source project moby, but a lot of people use the term docker
when they mean containers.
Containers are a way to package applications with their dependencies using OS-level virtualization. You can run many containers on the same machine (physical or virtual) and they will all share the same OS kernel. This approach allows for very lightweight isolation and decent security. Although, it’s not as good as a full-fledged virtual machine. Windows containers emerged later.
There is a lot of material about container technology out there. Here we will barely scratch the surface.
Containers use Linux kernel namespaces to isolate every aspect of the container from other containers. Docker uses the following namespaces:
pid
namespace: Process isolation (PID: Process ID).net
namespace: Managing network interfaces (NET: Networking).ipc
namespace: Managing access to IPC resources (IPC: InterProcess Communication).mnt
namespace: Managing filesystem mount points (MNT: Mount).uts
namespace: Isolating kernel and version identifiers. (UTS: Unix Timesharing System).
The following diagram illustrates the relationship between the OS, the Docker runtime engine, and the containers that contain the applications and their dependencies.
Get hands-on with 1400+ tech skills courses.