Docker provides a lightweight virtualization solution with zero overhead. This article demonstrates how to install Docker on Ubuntu. It also outlines the deployment of a Docker container application, NGINX, on Ubuntu.
Containerization is currently popular in the software development community as an alternative to virtualization. It enables us to encapsulate (containerize) software with all its dependencies and the runtime environment so that it can run uniformly across various infrastructures and platforms. In general, running software in containerized environments consumes lesser computing resources than running software in multiple virtual machines, because each virtual machine requires its own copy of the operating system. This article compares a virtual machine to a Docker container and demonstrates how to install and configure a Docker containerization environment. Finally, deployment of NGINX as a sample Docker container application is also demonstrated.
Virtual machine vs Docker container
Docker is a software development platform enabling virtualization on a single host with different operating systems. It enables rapid software delivery by separating infrastructure from applications. Docker virtualization is performed at the system level, using Docker containers, unlike hypervisors, which produce VMs. As depicted in Figure 1, Docker containers operate the operating system of the host. This also improves an application’s efficiency and security. Also, as containers consume fewer resources than virtual machines, we can deploy more containers on the same hardware.
A comparison of VM and Docker containers is given in Table 1.
Virtual machine (VM) | Docker |
Hardware-level isolation | OS-level isolation |
Slow booting (minutes) | Fast booting (sec) |
Heavyweight (Gigabyte) | Much smaller in size than a VM (KB/ MB) |
VMs can simply migrate to new hosts | Containers are destroyed and rebuild |
Huge computing resources required | Less computing resources required |
Why Docker is popular
Docker provides a lightweight virtualization solution with zero overhead. It is currently widely used across a variety of sectors. Containers make it possible for developers to deploy a program along with all of its requirements and configurations, including libraries and other dependencies, as a single package, which can then be distributed to end users. Docker is gaining popularity in the world of technology for a variety of reasons, a few of which are mentioned below:
- Efficient resource usage
- Simple configuration
- Enhanced developer productivity
- Provides application isolation
- Aditya Bhardwaj
Fast application development
Installing Docker on Ubuntu/Linux
Before installing the Docker Engine on a new host system, we must configure the Docker repository. The user can then update and install Docker from the repository. The steps for installing Docker and running the example application are listed below.
Step 1: Perform an update on the package index for apt, and then install the necessary modules to enable apt to use HTTPS archives.
$ apt-get -y install apt-transport-https ca-certificates curl
Step 2: Download GPG key for Docker.
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
Step 3: Configure the repository with the following command:
$ add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”
Step 4: Once you have downloaded your apt package, install Docker Engine by executing the following commands:
$ apt-get update $ apt-get -y install docker-ce
Step 5: Now verify the installation. Executing the Ubuntu image will allow you to confirm that the Docker Engine was successfully installed.
$ Docker pull ubuntu
Docker pulls a command to download the required image from the Docker hub, as shown in Figure 2.
Step 6: NGINX is free software used for many different purposes, including web serving, media streaming, reverse proxying, caching, and load balancing. Use the command given below to download the NGINX Docker container image:
$ Docker container run Nginx
When we run the above command, Docker looks for the image repository and downloads the latest version of NGINX. Thus, the NGINX container is created and gets a virtual IP inside the private bridge network depicted in Figure 3.
The following command will display a list of all currently active containers. Successful deployment of NGINX Docker containers can be accessed as shown in Figure 4.
$ docker ps
Table 2: Frequently used commands for Docker in a production environmentCommand Purpose
Command | Purpose |
$ docker – – version | To find the version of Docker |
$ “docker start “container _name” | Start your container |
$ “docker stop “container _name” | Stop running container |
$ docker kill “container _name” | Kill a container |
$ docker top “container _name” | To list the running processes within a container |
$ docker container stats “container _name” | To get the CPU and memory usage by a container |
docker info | Get information on the container |
Docker can provide a containerization platform that bundles our application and all of its dependencies inside a Docker container to ensure that our application functions seamlessly in any environment. Containerization simply eliminates this problem by bundling (containerizing) the software code with the related configuration files, libraries, and other run-time dependencies. Thus, containers are much more lightweight than virtual machines, resulting in their widespread adoption across industries.