Commercial software development needs umpteen software packages interacting seamlessly with each other while also being under active development themselves. Cross-platform compatibility is a crucial requirement for several software in deployment. Various tools are used to either create the required software environment before running the software or ship the complete package to users.
This article explains the concept of containerization using Docker, its use, and its significance in software development.
What is Software Containerization?
Containerization is one of the several OS-level virtualization tools where multiple instances of user space can exist independently on the same host operating system. The kernel allows each instance to work on a predefined set of allocated hardware resources and resource access, immune to other simultaneously operational containers or system-wide programs.
Softwares running inside containers can function reliably assuming that the resources they see are completely available to them. Containers ensure hardware availability, data security, and computational resource management.
A software can be packaged with all the supporting libraries, programming languages, configuration files, and with desired compute and hardware driver requirements inside a container ready to be deployed on different platforms, whether different OS’s like Windows/Mac/Ubuntu or different architectures like x86/ARM. Often, multiple softwares are deployed across multiple containers to maintain modular structure and interdependence hierarchy.
What is Docker?
Docker is a platform that provides services for OS-level containerization. Docker is analogous to a virtual machine in functionality but differs in behavior. A virtual machine creates a completely new virtual OS hosted on the current OS while Docker container uses the same kernel, making it lightweight (as it only has the possibly missing software elements not expected to be on the host OS) yet standalone.
Docker allows developers to write code without worrying about a different architecture on the testing or deployment platform and, likewise, helps streamline software maintenance by maintaining consistency across all deployments while reducing the number of potential differences two instances of the same application running on two machines can have.
Significance of Docker
Docker has been heavily supported by software developer communities and companies. Since its inception, Docker has found backers in Microsoft, IBM, Red Hat, Google, and IBM. It provides consistent development and testing environments, no conflicts with host OS and resource management via easy-to-use command line interface. Dockers uses several low-level tools and services from the Linux kernel (outside the scope of this article) for containerization which make it efficient and fast.
Concepts in Docker
The Docker software has the Docker daemon dockerd which manages multiple containers running on the host OS. The client tool docker is used to interact with the daemon via command-line interface or the Docker API.
Docker has several images. A docker image is a package of all the softwares, dependencies, and files bundled together in the dormant state. An activated instance of the image is called a container. It is analogous to a C++ class (image) and the object(container) created at runtime.
A registry is a repository or storage location for Docker images stored in the cloud, with private or public access. The two largest public registries with community contributions are Docker Hub and Docker Cloud.
Docker Hub provides several ready to use images for different OS’s, architectures, and applications like devops tools, databases, security, and storage. The complete list of publicly available images is available on the Docker Hub. A user can also save and push/pull private images on Docker Hub for cloud backup and portability.
The Docker Engine is the main software application running on the host machine. It works on the client-server relationship between the daemon or the server and the client is either the command-line interface or the REST API.
Using Docker CE (Community Edition)
As a first experiment, it is safe to try the open source community edition of Docker: docker-ce. Docker CE is a free tool for individuals with monthly edge releases as well as stable releases. We are installing the stable release here.
Remember: Docker needs root privileges for all commands, so you need to add sudo before each command. Also, all commands here are applicable to Ubuntu 16.04 LTS.
// Add the GPG key [email protected]:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - // Add Docker CE stable release to aptitude repo [email protected]:~$sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" [email protected]:~$ sudo apt-get update [email protected]:~$ sudo apt-cache policy docker-ce // Install Docker Community Edition [email protected]:~$ sudo apt-get install -y docker-ce // Confirm the version of installed Docker [email protected]:~$ docker --version
How to Use a Docker Image from Docker Hub
- The Docker CLI has the docker [OPTIONS] COMMAND template
- To obtain a list of command line options, just type docker
- To download and run the hello-world Docker image from Docker Hub, run the following command:
[email protected]:~$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
- You can see that Docker prints the steps executed for the command. This confirms that Docker was installed correctly and functional.
- As mentioned earlier, a container is a running instance of the image, so, to save the current state of the container as an image and potentially push it to the registry; stop the container commit the changes
Docker is one of the most-used tools in large organizations. This article was an introduction to the notion of containerization and how Docker works. An article describing the end-to-end use of Docker for software development should be next.