System Administration Video Tutorials

How to Install and Use Docker on Ubuntu

Introduction

Docker is an application that simplifies the process of managing application processes in containers. Containers let you run your applications in resource-isolated processes. They’re similar to virtual machines, but containers are more portable, more resource-friendly, and more dependent on the host operating system.

There are two ways

The slow way:

Prerequisites

OS requirements

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

  • Ubuntu Focal 20.04 (LTS)
  • Ubuntu Eoan 19.10
  • Ubuntu Bionic 18.04 (LTS)
  • Ubuntu Xenial 16.04 (LTS)

Uninstall old versions

Older versions of Docker were called dockerdocker.io, or docker-engine. If these are installed, uninstall them:

$ sudo apt-get remove docker docker-engine docker.io containerd runc

Install using the repository

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

SET UP THE REPOSITORY

    1. Update the apt package index and install packages to allow apt to use a repository over HTTPS:
      $ sudo apt-get update
      
      $ sudo apt-get install \
          apt-transport-https \
          ca-certificates \
          curl \
          gnupg-agent \
          software-properties-common
      
    2. Add Docker’s official GPG key:
      $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
      

      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.

      $ sudo apt-key fingerprint 0EBFCD88
      
      pub   rsa4096 2017-02-22 [SCEA]
            9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
      uid           [ unknown] Docker Release (CE deb) <[email protected]>
      sub   rsa4096 2017-02-22 [S]
      
    3. Use the following command to set up the stable repository.

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

INSTALL DOCKER ENGINE

  1. Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:
     $ sudo apt-get update
     $ sudo apt-get install docker-ce docker-ce-cli containerd.io
  2. Verify that Docker Engine is installed correctly by running the hello-world image.
    $ sudo docker run hello-world

The Quick Way:

  1. Download the Install Script:
    $ wget https://gist.githubusercontent.com/MazenElzanaty/778f21272841b4931ba9e289ac74c5fd/raw/d5bd5d5c72854c6a46af81ddecce1d434f200273/install-docker.sh
  2. Make it Executable:
    $ chmod +x install-docker.sh
  3. Run it as root:
    $ sudo ./install-docker.sh

Video:

https://youtu.be/vyKtzQqNgtA