Docker

How to Install Docker on Ubuntu

With this example, we are going to demonstrate how to install Docker on Ubuntu.

1. What is Docker?

Docker is a platform used to develop, deploy, and run applications by using containers. Docker consists of:

  • Docker Engine – lightweight and powerful open source containerization technology combined with a workflow for building and containerizing your applications.
  • Docker Hub – SaaS (Software as a Service) service for sharing and managing your application stacks.

 

2. What is Ubuntu?

Ubuntu is a free and an open-source Linux distribution based on Debian.
Ubuntu is an open source software operating system that runs from the desktop, to the cloud, to all your internet connected things.
Ubuntu is officially released in three editions:

  • Ubuntu Desktop for personal computers
  • Ubuntu Server for servers and the cloud, and
  • Ubuntu Core for the Internet of things devices and robots.

3. Steps for Installation of Docker on Ubuntu

To complete the installation of Docker on Ubuntu, It involves two steps:

  1. Installation of Ubuntu Operating System
  2. Installation of Docker on Ubuntu System

4. Installation of Ubuntu Operating System

I am using my laptop containing Microsoft Windows 10 Pro Operating System for explaining “Docker Install on Ubuntu Example

How to install Ubuntu on a machine containing Microsoft Windows 10 Pro Operating System and Version: 10.0.17763?

To accomplish this task, Understand the concept of Virtual Machine.

4.1 What is a Virtual Machine?

A Virtual Machine (VM) is a software program or operating system that not only exhibits the behavior of a separate computer but is also capable of performing tasks such as running applications and programs like a separate computer. A virtual machine, usually known as a guest (for this example, Virtual machine contains Ubuntu) is created within another computing environment referred to as a “host” (in my case, the host is Microsoft Windows 10 Pro Operating System). Multiple virtual machines can exist within a single host at one time. Virtual machines are becoming more common with the evolution of virtualization technology.

Virtual machines are computers whose hardware components are emulated by the host computer. A virtual machine is also known as a guest.

The following are free Virtual Machine Software available :

I am going to explain this “Docker Install on Ubuntu example” by installing Oracle VM VirtualBox on my machine Microsoft Windows 10 Pro and Version: 10.0.17763.

4.2 What is Oracle VM Virtual Box?

Oracle VM VirtualBox is a free, open source, cross-platform application for creating, managing and running virtual machines (VMs). 
Oracle VirtualBox enables you to set up one or more virtual machines (VMs) on a single physical machine, and use them simultaneously, along with the actual machine. Each virtual machine can execute its own operating system, including versions of Microsoft Windows, Linux, BSD, and MS-DOS.

VirtualBox runs on Windows, Linux, Macintosh, and Solaris hosts and supports a large number of guest operating systems including but not limited to Windows (NT 4.0, 2000, XP, Server 2003, Vista, Windows 7, Windows 8, Windows 10), DOS/Windows 3.x, Linux (2.4, 2.6, 3.x and 4.x), Solaris and OpenSolaris, OS/2, and OpenBSD.

4.3 Installation of Oracle VM Virtual Box

Download Oracle VM Virtual Box from the following links: https://www.virtualbox.org/wiki/Downloads (or) https://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html

Docker Install on Ubuntu - Step 1
Oracle VM VirtualBox Installation – Step 1

For this example: Click on Windows Hosts.

It downloads the file: VirtualBox-6.0.6-130049-Win.exe (Application) on your system. Double Click on this file. It installs this software. The steps are as shown below:

Docker Install on Ubuntu - Step 2
Oracle VM VirtualBox Installation – Step 2
Docker Install on Ubuntu - Step 3
Oracle VM VirtualBox Installation – Step 3
Docker Install on Ubuntu - Step 4
Oracle VM VirtualBox Installation – Step 4
Docker Install on Ubuntu - Step 5
Oracle VM VirtualBox Installation – Step 5
Docker Install on Ubuntu - Step 6
Oracle VM VirtualBox Installation – Step 6
Docker Install on Ubuntu - Step 7
Oracle VM VirtualBox Installation – Step 7
Docker Install on Ubuntu - Step 8
Oracle VM VirtualBox Installation Complete – Step 8

Search for Oracle VM VirtualBox desktop icon after the installation:

Docker Install on Ubuntu - Desktop Icon
Click on Desktop Icon (Oracle VM VirtualBox)

Click on it, It opens the Oracle VM VirtualBox Manager main screen as shown below:

Oracle VM VirtualBox Manager – Main Screen

4.4 Download Ubuntu Desktop

Ubuntu Desktop is designed for desktop and laptop PCs.

You can download the latest version of Ubuntu Desktop disk image (iso) from this website: https://www.ubuntu.com/desktop

ISO file, which is also known as a disc image, has .iso file extension.

Download Ubuntu Desktop Image (ubuntu-18.10-desktop-amd64.iso) from the following links: http://nl.releases.ubuntu.com/18.10/
http://releases.ubuntu.com/18.10/

To demonstrate “Docker Install on Ubuntu Example“, I am going to use :

ubuntu-18.10-desktop-amd64.iso ubuntu desktop image file.

Enable Virtualization Technology:
Enable Virtualization Technology by entering the PC BIOS or by accessing your PC BIOS for Windows.

Uncheck or Disable Hyper-V on Windows OS:
Right Click on Windows Icon-> App and Features -> Click on Programs and Features -> Turn Windows Features on or off – Hyper V should be disabled (unchecked)

Hyper-V is Unchecked (Disabled)

4.5 Create a New Virtual Machine

I had already installed CentOS in a Virtual Machine on the Oracle VM Virtual Manager. Please ignore this when you follow the steps.

Oracle VM Virtual Manager containing CentOS installed in a Virtual Machine

Now, Please follow the below steps to create a new virtual machine and to install Ubuntu in the new Virtual Machine:

Select Machine -> New menu option on Oracle VM VirtualBox Manager Dashboard:

Create a New Virtual Machine – Step 1

Enter the Name: Ubuntu, Type: Linux and Version: Ubuntu (64-bit).

Create a New Virtual Machine – Step 2

Enter 2048 MB.

Create a New Virtual Machine – Step 3

Select the option as shown below:

Create a New Virtual Machine – Step 4

Select the option as shown below:

Create a New Virtual Machine – Step 5

Select the option as shown below:

Create a New Virtual Machine – Step 6

Enter the Virtual Hard Disk Size as 20 GB.

Create a New Virtual Machine – Step 7

A new Virtual Machine with name Ubuntu has been created with the following configuration as shown below:

Create a New Virtual Machine – Step 8

Click on Settings button:

Create a New Virtual Machine – Settings – Step 9

(or) click on Settings icon button:

Create a New Virtual Machine – Settings – Step 9 (another Setting Option)

Click on General tab:

Create a New Virtual Machine – Settings – Step 10

Click on Network Tab:

In Adapter 1
Enable Network Adapter.
Select Attached to: Bridged Adapter.
It automatically picks up the Name as Intel (R) Ethernet Connection (4) I219-LM based on your machine network configuration.

Create a New Virtual Machine – Settings – Step 11

A new Virtual Machine with the name Ubuntu has been created with the above settings. Now, we need to install Ubuntu OS on this Virtual Machine.

4.6 Install Ubuntu on Virtual Machine

Please do the following steps to install Ubuntu OS on the new Virtual Machine named Ubuntu that we have created:

Right Click on Ubuntu Virtual Machine Name -> Click on Start -> Normal Start

Install Ubuntu on the New Virtual Machine -Normal Start -Step 1

Another way: Click on Green Arrow (Start) – Normal Start:

Install Ubuntu on the New Virtual Machine -Normal Start -Step 2

Select Start-up disk:

Select the downloaded Ubuntu desktop image (ubuntu-18.10-desktop-amd64.iso ) from your local system:

Install Ubuntu on the New Virtual Machine -Normal Start -Step 3

Click on “Install Ubuntu”.

Install Ubuntu on the New Virtual Machine -Normal Start -Step 4

Select English as Language to use during the Installation process:

Install Ubuntu on the New Virtual Machine -Normal Start -Step 5

Select the below options:

Install Ubuntu on the New Virtual Machine -Normal Start -Step 6

Select the below option:

Install Ubuntu on the New Virtual Machine -Normal Start -Step 7

Click Continue.

Install Ubuntu on the New Virtual Machine -Normal Start -Step 8

Select your local date and time by selecting the location of your country:

Install Ubuntu on the New Virtual Machine -Normal Start -Step 9

Provide your name, computer’s name, user name and password. Click Continue.

Install Ubuntu on the New Virtual Machine -Normal Start -Step 10

Installation is in progress:

Install Ubuntu on the New Virtual Machine -Normal Start -Step 11

Installation is in Progress:

Install Ubuntu on the New Virtual Machine -Normal Start -Step 12

Ubuntu is now successfully installed and ready for you to use. Go Ahead and Reboot to start using it. Click the Restart Now button.

Ubuntu Installation is Complete

Ubuntu is starting:

Ubuntu is now starting

Ubuntu OS is up and running now. It is prompting the User Suresh to login with his Credentials:

Ubuntu is Up and Running. Prompting the User Suresh to log in.

User Suresh is now logging in with his Credentials. Clicks Sign In button.

User Suresh is logging in.

Ubuntu Operating System main screen is displayed after the User Suresh has successfully authenticated and logged in:

Ubuntu Main Screen

Settings: Click Ubuntu Software -> Select Software & Updates:

Ubuntu Software – Software & Updates

Select Download From: Main Server

Ubuntu Software – Software & Updates

Other Software: Uncheck all the checkboxes

Ubuntu Software – Software & Updates

Switching Ubuntu from screen GUI (Graphical User Interface) to CUI (Character User Interface) by typing Terminal in the Search Box:

Ubuntu Terminal Option

Ubuntu is displaying command line prompt for the user who logged in and it is ready to accepts commands from the User Suresh:

Ubuntu Command line Prompt

5. Installation of Docker on Ubuntu in the Virtual Machine

Let us see know how to install Docker on Ubuntu OS in the new Virtual Machined named as Ubuntu.

5.1 Prerequisites

To get started with Docker CE (Community Edition) on Ubuntu, make sure you meet the prerequisites, then install Docker.

OS Requirements:

To install Docker CE, you need the 64-bit version of one of these Ubuntu versions:

  • Cosmic 18.10
  • Bionic 18.04 (LTS)
  • Xenial 16.04 (LTS)

Docker CE is supported on x86_64 (or amd64), armhfarm64s390x (IBM Z), and ppc64le (IBM Power) architectures.

Uninstall Old Docker Versions:

sudo apt-get remove docker docker-engine docker.io containerd runc – Older versions of Docker were called dockerdocker.io, or docker-engine. If these are installed, uninstall them.

It’s ok, if apt-get reports that none of these packages are installed.

The contents of /var/lib/docker/, including images, containers, volumes, and networks, are preserved. The Docker CE package is now called docker-ce.

Uninstall Older Docker Versions

5.2 Install Docker Community Editions (CE)

You can install Docker CE in different ways, depending on your needs:

  • Most users set up Docker’s repositories and install from them, for ease of installation and upgrade tasks. This is the recommended approach.
  • Some users download the DEB package and install it manually and manage upgrades completely manually. This is useful in situations such as installing Docker on air-gapped systems with no access to the internet.
  • In testing and development environments, some users choose to use automated convenience scripts to install Docker.

5.2.1 Install using the Repository

Before you install Docker CE for the first time on a new host machine, you need to set up the Docker repository. Later, you can install and update Docker from the repository.

5.2.2 Setup the Repository

sudo apt-get update – Update the apt package index.
apt list –upgradable – List all packages which are scheduled for an update.

Packages Index
Update Packages Index

sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common – Install packages to allow apt to use a repository over HTTPS:

Use Repository over HTTPS

sudo apt install curl – cURL is a computer software project providing a library and command-line tool for transferring data using various protocols.

Install Curl
Install Curl (Completed)

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add – – Add Docker’s official GPG key

sudo apt-key fingerprint 0EBFCD88 – Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.

Add Docker’s official GPG key

Use the following command to set up the stable repository. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below.

sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”

Set up the Stable Repository

5.2.3 Install Docker CE

sudo apt-get update – Update the apt package index

Update Package Index
Update Package Index

sudo apt-get install docker-ce docker-ce-cli containerd.io – Install the latest version of Docker CE and containerd:

Install the latest version of Docker CE and containerd
Install the latest version of Docker CE and containerd

To install a specific version of Docker CE, list the available versions in the repo, then select and install:

apt-cache madison docker-ce – List the versions available in your repo.

List the Docker CE Versions available in the Repo

sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io – Install a specific version using the version string from the second column, for example, 5:18.09.1~3-0~ubuntu-xenial.

sudo docker run hello-world – Verify that Docker CE is installed correctly by running the hello-world image.

Verify Docker CE is properly installed

This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

sudo systemctl status docker – Verify the Status of Docker (Running)

Verify the Status of Docker

sudo usermod -aG docker suresh – Add a user to the docker group

After running the above command, you need to log out and log back into your computer (or terminate your SSH session and re-connect in case you are logged in using SSH) – else, the group change does not take effect.

Running groups should show you that you now belong to the docker group:

groups – Displays the collection of Users

ps aux | grep dockerd – The Docker client communicates usually with the daemon either locally, via the unix socket /var/run/docker.sock, or over a network via a tcp socket. 

Add User Suresh to Docker Group & Communication Docker Client and Daemon

docker – To view all available subcommands

Docker Command

docker info – To view system-wide information

Docker Info Command

docker images – List Images

docker search ubuntu – Search the Docker Hub for images (ubuntu)

Docker Images and Docker Search

shudown -h now – Linux Command to power off the machine (virtual machine) .

Power off Virtual Machine (Ubuntu)

6. Summary

In this Docker Install on Ubuntu Example we have learned the following:

  1. Downloading, Installing and Configuring Oracle VM VirtualBox on Windows 10 OS (host).
  2. Creating and Configuring a New Virtual Machine using Oracle VM VirtualBox.
  3. Downloading Ubuntu.
  4. Installing and Configuring Ubuntu on the new Virtual Machine (guest).
  5. Downloading, Installing Docker CE on Ubuntu which is on Virtual Machine (guest).
  6. Executing Docker Commands and pulling images from the public Docker Hub Registry.

Last updated on Feb. 27th, 2022

Suresh Kumar

He holds a Master's degree in Computer Applications from the University of Madras. He is a Senior Solution Architect with over 20 years of experience in Java, J2ee, .Net, Mobile, Cloud and DevOps Technologies. He is actively involved in all the project phases (Pre-Sales and Post-Sales, Initiation, Configuration Management, Planning, Design, Architecting, Tracking and Monitoring, Scheduling, Testing, Estimation, Closure, Delivery) in his Projects. He holds experience in Banking, E-Commerce, Travels, Finance, Automobiles, Insurance, Services domains. He has implemented various methodologies ( Waterfall, Spiral, Agile Scrum, Kanban) in his projects. He is a Sun Certified Java Programmer, Sun Certified Java Web Component Developer, Sun Certified Java Architect, Microsoft Certified Visual Studio & TFS Administrator, and PMI Certified PMP. He is currently working as a Senior Solution Architect in Indian Government Project using Angular 8, ESRI ArcGIS, JSF PrimeFaces, Spring, Restful web services, PostgreSQL, MongoDB.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button