Explore Courses
course iconScrum AllianceCertified ScrumMaster (CSM) Certification
  • 16 Hours
Best seller
course iconScrum AllianceCertified Scrum Product Owner (CSPO) Certification
  • 16 Hours
Best seller
course iconScaled AgileLeading SAFe 6.0 Certification
  • 16 Hours
Trending
course iconScrum.orgProfessional Scrum Master (PSM) Certification
  • 16 Hours
course iconScaled AgileSAFe 6.0 Scrum Master (SSM) Certification
  • 16 Hours
course iconScaled Agile, Inc.Implementing SAFe 6.0 (SPC) Certification
  • 32 Hours
Recommended
course iconScaled Agile, Inc.SAFe 6.0 Release Train Engineer (RTE) Certification
  • 24 Hours
course iconScaled Agile, Inc.SAFe® 6.0 Product Owner/Product Manager (POPM)
  • 16 Hours
Trending
course iconIC AgileICP Agile Certified Coaching (ICP-ACC)
  • 24 Hours
course iconScrum.orgProfessional Scrum Product Owner I (PSPO I) Training
  • 16 Hours
course iconAgile Management Master's Program
  • 32 Hours
Trending
course iconAgile Excellence Master's Program
  • 32 Hours
Agile and ScrumScrum MasterProduct OwnerSAFe AgilistAgile CoachFull Stack Developer BootcampData Science BootcampCloud Masters BootcampReactNode JsKubernetesCertified Ethical HackingAWS Solutions Architect AssociateAzure Data Engineercourse iconPMIProject Management Professional (PMP) Certification
  • 36 Hours
Best seller
course iconAxelosPRINCE2 Foundation & Practitioner Certification
  • 32 Hours
course iconAxelosPRINCE2 Foundation Certification
  • 16 Hours
course iconAxelosPRINCE2 Practitioner Certification
  • 16 Hours
Change ManagementProject Management TechniquesCertified Associate in Project Management (CAPM) CertificationOracle Primavera P6 CertificationMicrosoft Projectcourse iconJob OrientedProject Management Master's Program
  • 45 Hours
Trending
course iconProject Management Master's Program
  • 45 Hours
Trending
PRINCE2 Practitioner CoursePRINCE2 Foundation CourseProject ManagerProgram Management ProfessionalPortfolio Management Professionalcourse iconAWSAWS Certified Solutions Architect - Associate
  • 32 Hours
Best seller
course iconAWSAWS Cloud Practitioner Certification
  • 32 Hours
course iconAWSAWS DevOps Certification
  • 24 Hours
course iconMicrosoftAzure Fundamentals Certification
  • 16 Hours
course iconMicrosoftAzure Administrator Certification
  • 24 Hours
Best seller
course iconMicrosoftAzure Data Engineer Certification
  • 45 Hours
Recommended
course iconMicrosoftAzure Solution Architect Certification
  • 32 Hours
course iconMicrosoftAzure DevOps Certification
  • 40 Hours
course iconAWSSystems Operations on AWS Certification Training
  • 24 Hours
course iconAWSDeveloping on AWS
  • 24 Hours
course iconJob OrientedAWS Cloud Architect Masters Program
  • 48 Hours
New
course iconCareer KickstarterCloud Engineer Bootcamp
  • 100 Hours
Trending
Cloud EngineerCloud ArchitectAWS Certified Developer Associate - Complete GuideAWS Certified DevOps EngineerAWS Certified Solutions Architect AssociateMicrosoft Certified Azure Data Engineer AssociateMicrosoft Azure Administrator (AZ-104) CourseAWS Certified SysOps Administrator AssociateMicrosoft Certified Azure Developer AssociateAWS Certified Cloud Practitionercourse iconAxelosITIL 4 Foundation Certification
  • 16 Hours
Best seller
course iconAxelosITIL Practitioner Certification
  • 16 Hours
course iconPeopleCertISO 14001 Foundation Certification
  • 16 Hours
course iconPeopleCertISO 20000 Certification
  • 16 Hours
course iconPeopleCertISO 27000 Foundation Certification
  • 24 Hours
course iconAxelosITIL 4 Specialist: Create, Deliver and Support Training
  • 24 Hours
course iconAxelosITIL 4 Specialist: Drive Stakeholder Value Training
  • 24 Hours
course iconAxelosITIL 4 Strategist Direct, Plan and Improve Training
  • 16 Hours
ITIL 4 Specialist: Create, Deliver and Support ExamITIL 4 Specialist: Drive Stakeholder Value (DSV) CourseITIL 4 Strategist: Direct, Plan, and ImproveITIL 4 Foundationcourse iconJob OrientedData Science Bootcamp
  • 6 Months
Trending
course iconJob OrientedData Engineer Bootcamp
  • 289 Hours
course iconJob OrientedData Analyst Bootcamp
  • 6 Months
course iconJob OrientedAI Engineer Bootcamp
  • 288 Hours
New
Data Science with PythonMachine Learning with PythonData Science with RMachine Learning with RPython for Data ScienceDeep Learning Certification TrainingNatural Language Processing (NLP)TensorFlowSQL For Data AnalyticsData ScientistData AnalystData EngineerAI EngineerData Analysis Using ExcelDeep Learning with Keras and TensorFlowDeployment of Machine Learning ModelsFundamentals of Reinforcement LearningIntroduction to Cutting-Edge AI with TransformersMachine Learning with PythonMaster Python: Advance Data Analysis with PythonMaths and Stats FoundationNatural Language Processing (NLP) with PythonPython for Data ScienceSQL for Data Analytics CoursesAI Advanced: Computer Vision for AI ProfessionalsMaster Applied Machine LearningMaster Time Series Forecasting Using Pythoncourse iconDevOps InstituteDevOps Foundation Certification
  • 16 Hours
Best seller
course iconCNCFCertified Kubernetes Administrator
  • 32 Hours
New
course iconDevops InstituteDevops Leader
  • 16 Hours
KubernetesDocker with KubernetesDockerJenkinsOpenstackAnsibleChefPuppetDevOps EngineerDevOps ExpertCI/CD with Jenkins XDevOps Using JenkinsCI-CD and DevOpsDocker & KubernetesDevOps Fundamentals Crash CourseMicrosoft Certified DevOps Engineer ExpertAnsible for Beginners: The Complete Crash CourseContainer Orchestration Using KubernetesContainerization Using DockerMaster Infrastructure Provisioning with Terraformcourse iconCertificationTableau Certification
  • 24 Hours
Recommended
course iconCertificationData Visualization with Tableau Certification
  • 24 Hours
course iconMicrosoftMicrosoft Power BI Certification
  • 24 Hours
Best seller
course iconTIBCOTIBCO Spotfire Training
  • 36 Hours
course iconCertificationData Visualization with QlikView Certification
  • 30 Hours
course iconCertificationSisense BI Certification
  • 16 Hours
Data Visualization Using Tableau TrainingData Analysis Using Excelcourse iconEC-CouncilCertified Ethical Hacker (CEH v12) Certification
  • 40 Hours
course iconISACACertified Information Systems Auditor (CISA) Certification
  • 22 Hours
course iconISACACertified Information Security Manager (CISM) Certification
  • 40 Hours
course icon(ISC)²Certified Information Systems Security Professional (CISSP)
  • 40 Hours
course icon(ISC)²Certified Cloud Security Professional (CCSP) Certification
  • 40 Hours
course iconCertified Information Privacy Professional - Europe (CIPP-E) Certification
  • 16 Hours
course iconISACACOBIT5 Foundation
  • 16 Hours
course iconPayment Card Industry Security Standards (PCI-DSS) Certification
  • 16 Hours
CISSPcourse iconCareer KickstarterFull-Stack Developer Bootcamp
  • 6 Months
Best seller
course iconJob OrientedUI/UX Design Bootcamp
  • 3 Months
Best seller
course iconEnterprise RecommendedJava Full Stack Developer Bootcamp
  • 6 Months
course iconCareer KickstarterFront-End Development Bootcamp
  • 490+ Hours
course iconCareer AcceleratorBackend Development Bootcamp (Node JS)
  • 4 Months
ReactNode JSAngularJavascriptPHP and MySQLAngular TrainingBasics of Spring Core and MVCFront-End Development BootcampReact JS TrainingSpring Boot and Spring CloudMongoDB Developer Coursecourse iconBlockchain Professional Certification
  • 40 Hours
course iconBlockchain Solutions Architect Certification
  • 32 Hours
course iconBlockchain Security Engineer Certification
  • 32 Hours
course iconBlockchain Quality Engineer Certification
  • 24 Hours
course iconBlockchain 101 Certification
  • 5+ Hours
NFT Essentials 101: A Beginner's GuideIntroduction to DeFiPython CertificationAdvanced Python CourseR Programming LanguageAdvanced R CourseJavaJava Deep DiveScalaAdvanced ScalaC# TrainingMicrosoft .Net Frameworkcourse iconCareer AcceleratorSoftware Engineer Interview Prep
  • 3 Months
Data Structures and Algorithms with JavaScriptData Structures and Algorithms with Java: The Practical GuideLinux Essentials for Developers: The Complete MasterclassMaster Git and GitHubMaster Java Programming LanguageProgramming Essentials for BeginnersSoftware Engineering Fundamentals and Lifecycle (SEFLC) CourseTest-Driven Development for Java ProgrammersTypeScript: Beginner to Advanced

How to Install Docker on Ubuntu

By Kanav Preet

Updated on May 26, 2021 | 8 min read | 9.29K+ views

Share:

Docker is a platform that packages the application and all its dependencies in the container so that the application works seamlessly. The Container makes the application run its resource in an isolated process similar to the virtual machines, but it is more portable. 

For a detailed introduction to the different components of a Docker container, you can check out Introduction to Docker, Docker Containers & Docker Hub. Also, don't forget to read about how to Install Jenkins on Ubuntu.

This tutorial covers the installation and use of Docker Community Edition (CE) on an Ubuntu 20.04 machine. 

Pre-requisites

Audience

This tutorial is meant for those who are interested in learning Docker as a container service 

System Requirements 

  1. Ubuntu 20.04 64-bit operating system. (If Linux OS is not in system, we can run docker using Virtual Box, PFB the steps) 
  2. A user account with sudo privileges 
  3. An account on Docker Hub to pull or push an image from Hub. 

Ubuntu Installation on Oracle Virtual Box 

If you want to use Ubuntu 20.04 without making any change to the Windows Operating system, you can proceed with the Oracle Virtual box.  

Virtual Box is free and open-source virtualization software from Oracle. It enables you to install other operating systems in virtual machines. It is recommended that the system should have at least 4GB of RAM to get decent performances from the virtual operating system. 

Below are the steps for downloading Ubuntu 20.04 on Oracle Virtual box:

Navigate to the website of Oracle Virtual Box, download the .exe file and get the latest stable version. 

1. Once done with downloading the virtual box, we can navigate to and download the  Ubuntu disk image (.iso file) by clicking on the download option 

2. Once the download has been completed for Ubuntu .iso file, open the virtual box and click on "New" present on top.  

3. Enter the details of your virtual machine by giving any name, type as "Linux " and Version as Ubuntu (64 bit)  

4. Choose the memory (RAM ) that needs to be allocated to the Virtual machine  and click on Next. (I have chosen 3000 MB) 

5. After the RAM allocation ,Click on  Create a virtual disk now. This serves as the hard disk of the virtual Linux system. It is where the virtual system will store its files

6. Now, we want to select the Virtual Hard Disk.  

7. We can choose either the “Dynamically allocated” or the “Fixed size” option for creating the virtual hard disk. 

8. Finally, we have  to specify our Ubuntu OS's size. The recommended size is 10 GB, but it  can be increased if required.

8. Finally, we have  to specify our Ubuntu OS's size. The recommended size is 10 GB, but it  can be increased if required.

9. Ubuntu OS is ready to install in Virtual Box, but before starting the Virtual system, we need to a make few changes in settings. Click on storage under the setting.  

10. Click on Empty under Controller IDE. Navigate to Attributes and browse the Optical Drive option. 

11. Choose the .iso file from the location where it is downloaded. Once selected, click on OK and start the Virtual box by clicking on start present on the Top menu.

12. Click ok and start the machine. 

13. Proceed with "Install Ubuntu" 

14. Under "Updates and other software" section, check "Normal installation", and the two options under “Other options” and continue.

15. In Installation type, check Erase disk and install Ubuntu.

16. Choose your current location and set up your profile. Click Continue.  

17. It may take 10-15 minutes to complete the installation 

18. Once the installation finishes, restart the virtual system

We are done with pre-request, and can now proceed with using this Ubuntu. 

Docker Installation Process on Ubuntu  

Method 1: Install Docker on Ubuntu Using Default Repositories 

One of the easiest ways is the installation of Docker from the standard Ubuntu 20.04 repositories, but It’s possible that the Ubuntu default repositories have not updated to the latest revision of Docker. It happens because in some cases Docker is not supporting that particular Ubuntu version. Therefore, there can be a scenario where  Ubuntu default repositories have not updated to the latest version. 

  • Log in to Virtual Box. Run “docker” as command to check if it is previously installed.
  • To install Docker on Ubuntu box, first update the packages. It will ask for a password. Enter it and allow the system to complete the updates.
sudo apt update
  • To install Docker from Ubuntu default repositories, use the below command:
sudo apt install docker.io 
  • To check the installed version, use the below: 
docker --version 

Since discussed above, it has installed the 19.03.8 version of docker whereas the latest version is 20.04  

Method 2: Install Docker from Official Repository 

For installing docker on ubuntu 20.04 with the latest version, we’ll proceed with enabling the Docker repository, importing the repository GPG key, and finally installing the package. 

  • To install the docker on Ubuntu box, update your existing list of packages. It will ask for a password. Enter it and allow the system to complete the updates.
sudo apt update  
sudo apt install apt-transport-https ca-certificates curl software-properties-common 
  • Import the repository’s GPG key using the following curl command: 
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 
  • Add the Docker APT repository to the system 
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  • Again, update the package database with the Docker packages 
sudo apt update 
  • Finally, install Docker using below command: 
sudo apt install docker-ce 
  • To check the installed version use below: 
docker --version
  • To start, enable and check the status of docker, use below command: 
sudo systemctl  status docker 
sudo systemctl  start  docker 
sudo systemctl  enable  docker 

To check system wide information regarding docker installation, we use the command “docker info”. Information that is shown includes the kernel version, number of containers and unique images. 

The output will contain details as given below, depending upon the daemon running: 

Source:

$ docker info 
Client: 
 Context:    default 
 Debug Mode: true 
Server: 
 Containers: 14 
  Running: 3 
  Paused: 1 
  Stopped: 10 
 Images: 52 
 Server Version: 1.13.0 
 Storage Driver: overlay2 
  Backing Filesystem: extfs 
  Supports d_type: true 
  Native Overlay Diff: false 
 Logging Driver: json-file 
 Cgroup Driver: cgroupfs 
 Plugins: 
  Volume: local 
  Network: bridge host macvlan null overlay 
 Swarm: active 
  NodeID: rdjq45w1op418waxlairloqbm 
  Is Manager: true 
  ClusterID: te8kdyw33n36fqiz74bfjeixd 
  Managers: 1 
  Nodes: 2 
  Orchestration: 
   Task History Retention Limit: 5 
  Raft: 
   Snapshot Interval: 10000 
   Number of Old Snapshots to Retain: 0 
   Heartbeat Tick: 1 
   Election Tick: 3 
  Dispatcher: 
   Heartbeat Period: 5 seconds 
  CA Configuration: 
   Expiry Duration: 3 months 
  Root Rotation In Progress: false 
  Node Address: 172.16.66.128 172.16.66.129 
  Manager Addresses: 
   172.16.66.128:2477 
 Runtimes: runc 
 Default Runtime: runc 
 Init Binary: docker-init 
 containerd version: 8517738ba4b82aff5662c97ca4627e7e4d03b531 
 runc version: ac031b5bf1cc92239461125f4c1ffb760522bbf2 
 init version: N/A (expected: v0.13.0) 
 Security Options: 
  apparmor 
  seccomp 
   Profile: default 
 Kernel Version: 4.4.0-31-generic 
 Operating System: Ubuntu 16.04.1 LTS 
 OSType: linux 
 Architecture: x86_64 
 CPUs: 2 
 Total Memory: 1.937 GiB 
 Name: ubuntu 
 ID: H52R:7ZR6:EIIA:76JG:ORIY:BVKF:GSFU:HNPG:B5MK:APSC:SZ3Q:N326 
 Docker Root Dir: /var/lib/docker 
 Debug Mode: true 
  File Descriptors: 30 
  Goroutines: 123 
  System Time: 2016-11-12T17:24:37.955404361-08:00 
  EventsListeners: 0 
 Http Proxy: http://test:test@proxy.example.com:8080 
 Https Proxy: https://test:test@proxy.example.com:8080 
 No Proxy: localhost,127.0.0.1,docker-registry.somecorporation.com 
 Registry: https://index.docker.io/v1/ 
 WARNING: No swap limit support 
 Labels: 
  storage=ssd 
  staging=true 
 Experimental: false 
 Insecure Registries: 
  127.0.0.0/8 
 Registry Mirrors: 
   http://192.168.1.2/ 
   http://registry-mirror.example.com:5000/ 
 Live Restore Enabled: false 

Note: In case you get below error after running “docker info” command, one way is to add sudo in front and run the command, OR you can refer to the same error-resolving steps mentioned under Running Docker Images section. 

Running Docker Images and Verifying the process: 

To check whether you can access and download the images from Docker Hub, run the following command: 

sudo docker run hello-world

In case of errors received after running the docker run command, you can correct it using the following steps, otherwise proceed with the next step of checking the image. 

ERROR: docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.35/containers/create: dial unix /var/run/docker.sock: connect: permission denied. See 'docker run --help'.   

  • Create the docker group if it does not exist 
sudo groupadd docker 
  • Add your user to the docker group. 
  sudo usermod -aG docker $USER   

Eg:- sudo usermod -aG docker kanav 

  • Run the following command or Logout and login again and run ( if that doesn't work you may need to reboot your machine first) 
 newgrp docker 
  • Check if docker can be run without root 
docker run hello-world 

If the problem still continues, try to reboot it and run the command. 

  • To check the image, use this command: 
sudo docker images 

Uninstall Procedure: 

Below are the common commands used to remove images and containers: 

sudo  apt-get  purge docker-ce docker-ce-cli containerd.io 

To completely uninstall Docker, use below: 

  • To identify what are the installed packages, this is the command: 
dpkg -l | grep -i docker
sudo apt-get purge -y docker-engine docker docker.io docker-ce docker-ce-cli 
sudo apt-get autoremove -y --purge docker-engine docker docker.io docker-ce   
  • To remove images, containers, volumes, or user created configuration files, these commands can be used: 
  • sudo rm -rf /var/lib/docker /etc/docker 
  • sudo rm /etc/apparmor.d/docker 
  • sudo groupdel docker 
  • sudo rm -rf /var/run/docker.sock  

Conclusion: 

If you found this Install Docker on Ubuntu blog relevant and useful, do check out the Docker-Training workshop from KnowledgeHut, where you can get equipped with all the basic and advanced concepts of Docker! 

Kanav Preet

8 articles published

Kanav is working as SRE in leading fintech firm having experience in CICD Pipeline, Cloud, Automation, Build Release and Deployment. She is passionate about leveraging technology to build innovative ...

Get Free Consultation

+91

By submitting, I accept the T&C and
Privacy Policy

Preparing to hone DevOps Interview Questions?