Ubuntu - Docker

Docker is a container service which allows one to run applications or even operating systems on a host operating system as containers. Containers are a new and exciting technology that has evolved over the last couple of years and being adopted by a lot of key organizations.

Docker is a company that develops these special containers for applications. The official website for Docker is https://www.docker.com/

Docker Official Website

As an exercise, let’s install a CentOS container on an Ubuntu system. CentOS is a Linux-based operating system from Red Hat. Thus, we will be running the CentOS system on top of Ubuntu. Following are the steps to have this in place.

Step 1 − The first step is to install the Docker application on Ubuntu server. Thus on the Ubuntu test server, run the following command to ensure that OS updates are in place.

sudo apt-get update             
Install Docker

Step 2 − Once all updates have been processed, issue the following command to get Docker installed.

sudo apt-get install -y docker.io

Docker Installed

Step 3 − Once the Docker packages are installed, we should receive an output message stating that the Docker process has started and is running. The Docker process is known as the Docker engine or Docker daemon.

Step 4 − To view the version of Docker running, issue the Docker info command.

Docker Version

Step 5 − The next step is to install our CentOS image on Ubuntu.

Docker has a special site called the Docker hub, which is used to store pre-built images for Docker. The link to the site is https://hub.docker.com/

Step 6 − Do a quick and simple sign-in process to be able to log into the site and see all the available Docker images.

Docker Images

Step 7 − Once logged in, click the Explore button to see all the available Docker images.

Click Explore

The two important points to note are −

  • The Docker pull command. This is the command to install the Docker image on Linux box.

  • The Docker details for the various versions of CentOS.

Available Docker Images

Step 8 − On Ubuntu box, run the command.

sudo docker pull centos:latest

The download of the Docker component starts and the CentOS Docker is downloaded. The name of the Docker image is centos:latest, which means that we have the latest Docker image for CentOS.

Step 9 − To see all the Docker images installed, issue the command

sudo docker images

In the following screenshot, we can see that the Docker image is just 196.8 MB in size, and this is the subset of the CentOS which now runs on Ubuntu system.

Docker Image size

Step 10 − To start CentOS, we need to issue a command to the OS to get a thread started. We can do this by running the following command.

sudo docker run -it centos /bin/bash

The above command does the following things −

  • Runs the CentOS Docker image.

  • Runs the image in interactive mode by using the -it option.

  • Runs the /bin/bash command as the initial process.